From TextureBuffer into PNMImage

I have a texture buffer and I would like to get the content of that buffer into a PNMImage from time to time (not every frame!).
getScreenshot() gives me a part of the main window, even if I set “prefer-parasite-buffer 0”.

After a search on the forum I bumped into “extractTextureData” but I’m afraid I don’t know how to use it"tex_buffer", 512, 512)
#more code here


and I only get this in the console:

:display:gsg:glgsg(error): No texture data for

How can I make this work?

You can either explicitly pass a texture to the buffer constructor:

tex=Texture()"tex_buffer", 512, 512, tex)
#more code here


or retrieve the texture that was automatically created for it like this:"tex_buffer", 512, 512)
#more code here


Hope this helps :slight_smile: .

“No texture data” could also simply indicate that it has not been rendered to yet.



Nothing gets written to disk. I had this problem some time ago what I wanted to remove alpha from a texture buffer (done that with a shader in the end), but this time I really need the image back - I want to use it to regenerate a geomipmap terrain and save the image to disk.

As for it not being rendered yet - I use the texture from this buffer like this:

        manager = FilterManager(self.altBuffer, self.altCam)
        self.tex = Texture()
        quad = manager.renderSceneInto(colortex=self.tex)
        quad.setShaderInput("tex", self.tex)        
        self.terrain.getRoot().projectTexture(color_ts , self.altBuffer.getTexture(), self.altCam)

and I see it projected flawlessly, also the buffer viewer (base.bufferViewer.toggleEnable()) shows the texture in the buffer.

Any more help?

Have you tried setting to_ram to True in the buffer constructor? If you don’t do this, the texture is still shown in the buffer viewer, but you cannot use it because it’s not available in system RAM memory.

Tried that just a second ago… had to do a hard reboot, my system just froze :cry:

to_ram is not what you want as you indicated that you don’t want to transfer the data every frame, but only once in a while.

The fact that you see something in the buffer viewer or with projectTexture indicates that the data is there when the buffer viewer or the projected texture is rendered, not at the time when you move it to the PNMImage. Try calling base.graphicsEngine.renderFrame() twice or something like that.

You could also look at the source code of base.screenshot. I believe that it uses getScreenshot methods on GraphicsOutput that can get your data in PNMImage right away without having to mess with any of this.

This is strange, I have no idea what I’ve done, but now it works just fine with the simple code from Epihaius.