Recuperating the Image

Hi all,

It would currently be useful to me to create a Python Object containing the visual output of Panda. I wondered if there was a way either of tweaking Panda :smiling_imp: , or using a Panda class to recuperate the rendered image into a sort of array, or any python Object.

Thanks for your time and suggestions!

When you render to an image it gets rendered to a texture on the GPU normally it does not send this texture back to CPU (its slow) but you can force it. After you got it on the CPU you can use the PnmImage class to do any thing you want, read and write pixels if you like!

Could you give me a simple example?
Taking a screenshot?

What?
Never heard of base.win.getTexture() ? :slight_smile:

You can then use PTAUChar (I think) to convert it to a PIL image, if you want.

in the manual you find 5 chapters on that:

Render-to-Texture and Image Postprocessing
Common Image Filters
Generalized Image Filters
Dynamic Cube Maps
Low-Level Render to Texture

Hmm. I just see base.win.getTexture() returns None.

treeform, those are unnecessary complicated. From Panda 1.5.0, there’s the amazing FilterManager class.
Here’s how to use it:

from direct.filter.FilterManager import FilterManager

fm = FilterManager(base.win, base.cam)
yourTexture = Texture()
fm.renderSceneInto(colortex = yourTexture)

#now do with yourTexture whatever you want.

Well, using your technique, I’ve tried the following:

    def __init__(self):
        self.fm = FilterManager(base.win, base.cam)
        self.tex=Texture()
        self.image=PNMImage()
        self.arrayhasbeencreated=False
        taskMgr.add(self.getImage,"getImage")
    def getImage(self,task):
        self.fm.renderSceneInto(colortex = self.tex)
        self.tex.store(self.image)
        self.size=(self.image.getXSize(),
                   self.image.getYSize())

Thats only part of the code,
at self.tex.store(self.image), I get the following error:

I’d like to know if anybody has an idea of how either to bypass this error or do something so it doesn’t happen(which can be quite the same thing).
Or is there an other solution than using textures and PNMImages?\

Hmm. For some reason, Panda3D tries to access the mipmap levels but can’t since they are not loaded into RAM.
I’m just fishing here, but does calling self.tex.setupTexture() or self.tex.prepare() do any good?
Otherwise you can try with different functions like makeRamImage.

The FilterManager class creates offscreen buffers with RTMBindOrCopy, which is the normal, fast way to create offscreen buffers. It means that the texture image is not available in system RAM, however.

You will have to create offscreen buffers with RTMCopyRam if you want the texture image to be accessible to system RAM. This is the slow way to render to texture (it’s slow because copying to system RAM is an expensive operation).

You’re probably best off not using the FilterManager class, but rather by creating an offscreen buffer yourself, using something like:

tex = base.win.makeTextureBuffer("tex", 256, 256, toRam = True)

David