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:

Initially:

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

self.viewCam.setPos(0.0,0.0,100)
self.viewCam.setHpr(0,-90,0)

And later:

self.viewBuffer.saveScreenshot(“screenshots/view.jpg”)

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:

/Daniel

Try replacing:

self.viewBuffer = base.win.makeTextureBuffer('ViewBuffer', 512, 512 ) 

with:

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

and then:

self.viewBuffer.saveScreenshot("screenshots/view.jpg")

with:

self.viewTex.write("screenshots/view.jpg")

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.

David

Thanks, that worked great! :slight_smile:

/Daniel