makeRamImage from a makeTextureBuffer (Teapot on TV example)

I’m trying to get the pixels out of a made texture bufer.

I started with the “Sample-Programs–Teapot-on-TV” sample.

I made the altBuffer a member of World() - using self.altBuffer()

Then at the end of the program I added:

w=World()
taskMgr.step()
taskMgr.step()
taskMgr.step()
taskMgr.step()
ramimage = w.altBuffer.getTexture().makeRamImage()
for i in range(0,ramimage.size()):
if (ramimage.getElement(i) != 0):
print ramimage.getElement(i)
run()

ramimage is always just all 0’s, as if nothing is really there… is the buffer getting constantly cleared or something?

Thanks!

makeRamImage() is an internal method, which creates an all-zero ram image. This is probably not the method you meant to be calling.

What you really want to do is make sure that you create your texture with toRam = True in the makeTextureBuffer() call (or, if you use the lower-level addOutput() call to create your offscreen buffer, then when you call buffer.addRenderTexture(), you need to pass RTMCopyRam instead of RTMBindOrCopy). This will ensure that that the data from the texture is copied to the CPU each frame, instead of being left on the graphics card. There is additional cost to this action, of course, but it is necessary if you want to be able to access the individual pixels from Python.

When you have set up your texture this way, then you can call texture.getRamImage() to retrieve its image.

David

Don’t forget to consult the generate API docs:

http://panda3d.org/apiref.php?page=Texture#makeRamImage