getTexture().write() crashes panda

I have an offscreen buffer that is indepentent from the onscren world. I’d like to take screenshots from that buffer. I try this, and it crashes panda.

offscreen = hidden.attachNewNode('offscreen') 
myBuffer = base.win.makeTextureBuffer('offscreen', 1024, 1024)
myCamera = base.makeCamera(myBuffer)
myCamera.reparentTo(hidden)

# this should work.  Look and see that img.jpg is there
myBuffer.saveScreenshot(Filename("img.jpg")) 

# this will make you sad.  It will crash at this line
myBuffer.getTexture().write(Filename("crashimg.jpg"))

The last line fails on “has_ram_image”. I can’t find this function anywhere. I grepped through the lastest version from cvs to no avail. I really only want to save something the size of the offscreen buffer, not the size of the screenshot. Actually, what I really want to is to get the phyiscal bits that make up the texture, so I can minipulate them with the Python Image Library.

Right; you can’t dump the texture image to file in this example, because the texture image doesn’t exist in system RAM. It is only on the graphics card. That is why the render-to-texture operation is so fast, since it never passes through system RAM.

If you wanted to dump just the buffer to a disk file, the saveScreenshot() call would do exactly that. Don’t be misled by the function name; it doesn’t take a screenshot of your desktop, but rather just writes the current buffer image (whatever size it is) to the disk file. So the resulting image will be exactly the same size as your buffer. (You could make an image of just part of your buffer by using a DisplayRegion, but it doesn’t sound like you need that.)

But if you just want the buffer as a PNMImage so you can manipulate its pixels directly, without writing it to disk first, use something like this:

p = PNMImage()
myBuffer.getScreenshot(p)

Incidentally, you don’t need to parent your offscreen scene graph to hidden. I’d recommend just creating it separate, like this:

offscreen = NodePath('offscreen')
myCamera.reparentTo(offscreen)

David