Following the few examples I found on the web, I managed to whip up this code:
import bge
contr = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
obj = contr.owner
texture = None
if "render_to_texture" in obj:
texture = obj["render_to_texture"]
else:
camera = scene.objects['Camera']
# create texture
matID = bge.texture.materialID(obj, 'MAcam_render_material')
texture = bge.texture.Texture(obj, matID)
# create source
texture.source = bge.texture.ImageRender(scene, camera)
texture.source.capsize = [640, 480]
texture.source.background = [255, 255, 255, 255]
obj["render_to_texture"] = texture
print(texture) # prints <VideoTexture.Texture object at ...>
print(bge.texture.imageToArray(texture.source, 'RGB')) # prints 'None'
# force a refresh
pixels = bytearray(640 * 480 * 4)
texture.source.refresh(pixels, "RGBA")
# print(pixels) # just prints an array of zeroes
if(texture.source.valid): # always 'False'
print(texture.source.image)
else:
print("No image available")
And placed this script to be run every few ticks on a plane object with the material 'cam_render_material' on it. But no matter what, I get empty arrays and None as a result
I've been pounding my head against the desk for the past three hours and heading nowhere. If someone has an hints, they'd be greatly appreciated.
I've added the blender file in question here, if someone wants to check it out