I’m sorry if this “render to texture” topic is all over the place :(.
I just want to render a camera to a permanent texture data block, not an external image, because it will be slow to write, (and I probably have to reload the image again to make the engine use it).
I can capture the image using the script below, but that is not a permanent storage, the moment I change scene, the rendered image is lost, and bge.texture.Texture(obj,0) is never modified apparently.
I read a lot of posts but they never solved my problem, thanks a lot.
import bge
from bge import logic
from bge import texture
controller = logic.getCurrentController()
obj = controller.owner
scene = logic.getCurrentScene()
objList = scene.objects
cam = objList['Camera_Capture']
Texture = bge.texture.Texture(obj,0)
source = bge.texture.ImageRender(scene,cam)
source.capsize = [640,480]
source.alpha = False
Texture.source = source
logic.texture = Texture
logic.texture.refresh(True)
EDIT: Here it is, in case someone wants it, I am using this to make a transition like the puzzle in Banjo Kazooie. First I capture the screen, and then a puzzle model (which uses that image) is animated to fade in/out.
#Capture screen to "logic.globalDict['Captured_Buffer']"
import bge
from bge import logic
from bge import texture
scene = logic.getCurrentScene()
objList = scene.objects
cam = objList['Camera_Capture']
Capture = bge.texture.ImageRender(scene,cam)
logic.globalDict['Captured_Buffer'] = bge.texture.imageToArray(Capture, 'RGB')
logic.globalDict['Captured_Size'] = Capture.size
#Paste screen "logic.globalDict['Captured_Buffer']" to texture 0, material 0
import bge
from bge import logic
from bge import texture
controller = logic.getCurrentController()
obj = controller.owner
Rendered_Texture = bge.texture.Texture(obj,0)
Rendered_Texture.source = bge.texture.ImageBuff()
Rendered_Texture.source.load(logic.globalDict['Captured_Buffer'] , logic.globalDict['Captured_Size'][0], logic.globalDict['Captured_Size'][1])
obj["Captured_Screen"] = Rendered_Texture
Rendered_Texture.refresh(True)