I am trying to create a picture based on what one of my
OrthographicCamera can see. LibGDX has a
ScreenUtils class that has a
getFrameBufferPixels method, but it does not what I want as I want to get only what one camera sees, not the whole screen.
You need to render what the camera sees to an FBO and then get the pixmap from the FBO itself.
// Construct an FBO and keep a reference to it. Remember to dispose of it. final FrameBuffer fbo = new FrameBuffer(Format.RGB565, width, height, false); //In your render method //Start rendering to the fbo. fbo.begin(); //From the camera's perspective. batch.setProjectionMatrix(camera.combined); batch.begin(); //Draw whatever you want to draw with the camera. batch.end(); // Finished drawing, get pixmap. Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, width, height); //Stop drawing to your fbo. fbo.end(); //Now you can draw your normal screen as usual.
This will draw whatever you draw with your batch to your FBO from your camera's perspective. Remember to reset the projection matrix when you want to render from your main camera.