Shooting virtual photos...

Started by rschwemm, May 16, 2011, 11:13:30 AM

Previous topic - Next topic

rschwemm

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!

rschwemm

Ok, I found a solution.
For those interested, it looks like this:

// 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!

EgonOlsen

FrameBuffer contains a getOutputBuffer-method that can be used to obtain the pixels from it.