Taking a screenshot

Hello,

I am trying to make a screenshot of the displayed scene, so I tried three solutions I found in this forum. :smile:

The problem is, I don’t get the expected result:

  • Solution #1 and #3: I obtain an image with my main menu (pixel2d) even if I called the method to close it before. So it seems the saved image doesn’t represent the latest state of the buffer.
  • Solution #2: I obtain an image without my main menu (pixel2d), but the image is way too dark compared to what I see on screen

I also tried this (https://discourse.panda3d.org/t/asynchronous-screenshot-grabbing/29024) but I get a python exception, so I assume this option is not yet in the latest stable release.

First one (https://discourse.panda3d.org/t/headless-screenshots/5819/2):

direct.showbase.ShowBase.ShowBase.screenshot(self.main,
                                             defaultFilename=False,
                                             namePrefix=fullpath)

Second one (https://discourse.panda3d.org/t/offscreen-screenshot-with-background-image/28563):

direct.showbase.ShowBase.ShowBase.screenshot(self.main,
                                             source=self.main.camNode.getDisplayRegion(0),
                                             defaultFilename=False,
                                             namePrefix=fullpath)

Third one (https://discourse.panda3d.org/t/taking-screenshots-in-a-thread/12413):

screenshot = self.main.win.getScreenshot()
screenshot.write(fullpath)

Is there another method to get clean screenshots?

Thanks for your help! :pray:

I think you are getting an outdated scene image due to double buffering. Use this method, you may have to call it twice immediately before creating a screenshot.

base.graphicsEngine.renderFrame()

2 Likes

Regarding “Solution #2”, are you perhaps using any post-processing effects, whether your own or via the use of something like “simplepbr”?

If so, then that might explain the discrepancy in brightness: there may be a post-processing step that’s being missed due to which camera is being used for the screenshot.

2 Likes

@serega-kkz: thank you, it solved my problem! :pray:

@Thaumaturge: I think you are right, this is probably due to simplepbr post-processing :wink:

2 Likes