[SOLVED] Render only one frame and other questions

Thank’s to ThomasEgi on IRC, here is how to move the rendered frame image from GPU to RAM, and then get it in a PNMImage object

from panda3d.core import PNMImage, PNMImageHeader
from direct.showbase.ShowBase import ShowBase

base = ShowBase()

# Rendering the frame
base.graphicsEngine.renderFrame()

# Creating a PNMImage (this is NOT a file format, it's a class provided by Panda3D for accessing and doing operations on image)
screenshot = PNMImage()
# Set the display region
dr = base.camNode.getDisplayRegion(0)
# Store the image from GPU to the RAM variable screenshot
dr.getScreenshot(screenshot)

# Example of operations: making an histogram
hist = PNMImage().Histogram() # Create an histogram object
screenshot.makeHistogram(hist) # create the histogram and store it in hist
print(hist.getNumPixels()) # print the number of unique pixels colors
print(hist.getCount(PNMImageHeader.PixelSpec(255,255,255, 255))) # print the count of all white opaque pixels

# To access a single pixel
# intensity = screenshot.getPixel(x, y)

For more infos:
panda3d.org/reference/devel/ … MImage.php

Also, be careful with Google, the manual pages referenced by the search engine are outdated, and for example you won’t find the makeHistogram() method there.

Note: this method is only useful if one frame is rendered, but if it is iterated over many frames, this will be slow. You should then better use a direct GPU operation, for example by using a shader.