jPCT - a 3d engine for Java => Support => Topic started by: rschwemm on May 16, 2011, 11:13:30 am

Title: Shooting virtual photos...
Post by: rschwemm on May 16, 2011, 11:13:30 am

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:

Thank you in advance!
Title: Re: Shooting virtual photos...
Post by: rschwemm 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 <--

Camera photoCamera = new Camera();


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

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!
Title: Re: Shooting virtual photos...
Post by: EgonOlsen on May 16, 2011, 05:00:39 pm
FrameBuffer contains a getOutputBuffer-method that can be used to obtain the pixels from it.