OK, it turned out that there are two problems with this:
1. There has to be a model on a scene with a material that uses your target texture otherwise it won't update and only the first frame will be rendered in it.
2. If you have only one camera, texture anyway stops updating after resize. You need to have a second camera that renders on screen normally, then it will work.
My code:
function Script:Start ()
self.tex = Texture:Create(512,512)
self.cam=tolua.cast(self.entity, "Camera")
self.cam:SetRenderTarget(self.tex)
self.mat=Material:Create()
self.mat:SetTexture(self.tex)
self.mat:SetShader("Shaders/Model/Diffuse.shader")
self.mdl = Model:Create()
self.mdl:AddSurface()
self.mdl:SetMaterial(self.mat)
end
function Script:UpdateWorld()
if Window:GetCurrent():KeyHit(Key.A) then
self.tex = Texture:Create(256,256)
self.cam:SetRenderTarget(self.tex)
self.mat:SetTexture(self.tex)
end
end
function Script:PostRender()
Context:GetCurrent():DrawImage(self.tex,0,0)
end
This is a script on first camera and there is a second camera that renders normally. This way everything works as expected. But if I delete the second camera, target texture stops updating and image on the screen freezes.
Any idea what's wrong?