Off-screen camera for overview screenshot

Hi all!

I would like to save screenshots at certain times showing a view of my “world” from above and I would like to do so without having to show the user another view. In the manual this seems simple enough but it didn’t quite work as I expected.

This should be the essential code:


self.viewBuffer =‘ViewBuffer’, 512, 512 )
self.viewCam = base.makeCamera( self.viewBuffer )
self.viewCam.reparentTo( render )
self.viewCam.node().getLens().setFov( base.camLens.getFov( ) )


And later:


But the resulting image has the same camera-transformation as the standard camera, i.e., I just get a “regular” screenshot…

Can you spot the problem? :slight_smile:


Try replacing:

self.viewBuffer ='ViewBuffer', 512, 512 ) 


self.viewTex = Texture('ViewTex')
self.viewBuffer ='ViewBuffer', 512, 512, self.viewTex, True ) 

and then:




This is necessary because the offscreen buffer you create might share space with your main window, which means you can’t just dump a screenshot directly from the buffer (it might have been overwritten with the main window output by the time you dump it). But you can dump a screen from the texture associated with the buffer.

Note that this requires adding True as a fifth parameter to makeTextureBuffer(), which means to copy the framebuffer data all the way back to RAM so it can be dumped to disk. This will be expensive, so to minimize the impact you should keep your viewBuffer disabled until you want a screenshot, with self.viewBuffer.setActive(False).

Another, completely different, solution would be to use base.graphicsEngine.makeOutput() instead of makeTextureBuffer, and specify appropriate parameters to insist that you get a genuinely separate offscreen buffer instead of a shared buffer with the main window. Then you wouldn’t have to associate it with a texture at all. But this can be unreliable on some drivers, and you’d still want to keep it disabled until you’re ready to dump the screenshot in any case.


Thanks, that worked great! :slight_smile: