Author Topic: Shooting virtual photos...  (Read 1088 times)

Offline rschwemm

  • byte
  • *
  • Posts: 18
    • View Profile
Shooting virtual photos...
« on: May 16, 2011, 11:13:30 am »
Hi!

I'm looking for a way to to take some kind of "screenshots". There are however some differences to actual screenshots:
Imagine to have multiple cameras in a world. What I want to to next is to save exactly what they're seeing at one exact point in time - preferably as image.
I had a look at the Camera and Projector classes, but I failed to find anything similar. Before I start implementing this on my own,
I want to make sure that:
  • I haven't missed something
  • I get some input on how to approach this first

Thank you in advance!

Offline rschwemm

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Shooting virtual photos...
« Reply #1 on: May 16, 2011, 02:46:32 pm »
Ok, I found a solution.
For those interested, it looks like this:

Code: [Select]
// class members:
BufferedImage photoImage;
FrameBuffer photoBuffer;
File photoFile;

...
// within some method:
// you might have to store the original camera here <--

photoBuffer.clear();
Camera photoCamera = new Camera();
photoCamera.setPosition(_from);
photoCamera.lookAt(_target);

world.setCameraTo(photoCamera);
world.renderScene(photoBuffer);
world.draw(photoBuffer);
photoBuffer.update();
photoBuffer.display(photoImage.getGraphics());

world.setCameraTo(cam.getJpctCamera()); // restore prev. cam

try{
ImageIO.write(photoImage, "png", photoFile);
}
catch (IOException ex){
...
}

As you can see, I have a dedicated (Software-) FrameBuffer for the purpose. I render into a BufferedImage object by getting its Graphics stuff.
There is no render-to-texture involved. The camera switching is a bit ugly but seems to work.

I'm not sure about the performance. But since it is only invoke once in a while I don't care so much.

Have fun!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Shooting virtual photos...
« Reply #2 on: May 16, 2011, 05:00:39 pm »
FrameBuffer contains a getOutputBuffer-method that can be used to obtain the pixels from it.