Snapshot of camera view for minimap i.e. NiftyGui [Solved]

Is it possible to take a snapshot of a camera view, and store this as an image file?

I’m sure there is solution for this, and suspect it can be done in different system levels.

Preferably the view wouldn’t need to be rendered to screen in advance.

To state the obvious: this would be usefull for making minimaps in the gui.Impostersystems could also use something like this.

Guess this topic is very related. I’ll check it, and post back here.

So here is the simplest solution I could come up with, it’s based on what I read in the post mentioned above.


int height = viewPort.getCamera().getHeight();

int width = viewPort.getCamera().getWidth();

BufferedImage rawFrame = new BufferedImage(width, height,BufferedImage.TYPE_4BYTE_ABGR);

ByteBuffer byteBuffer = BufferUtils.createByteBuffer(width * height * 4 );

renderManager.getRenderer().readFrameBuffer(viewPort.getOutputFrameBuffer(), byteBuffer);

Screenshots.convertScreenShot(byteBuffer, rawFrame);



What it does is take a screenshot of whatever is rendered last in a ViewPort, and store it as a file. The viewPort must be active on screen, but viewPorts are pretty flexible, so I think it will work for most purposes.