MartFayer Posted September 14, 2016 Share Posted September 14, 2016 How to change the size of the texture resolution? I create texture . Texture* Tex = Texture::Create(512, 512); camera->SetRenderTarget(Tex); draws its... OK... context->DrawImage(Tex,0,0); It is necessary to change the size of the texture . Here it does not work: camera->SetRenderTarget(0); Tex->Release(); Texture* CamTex2 = Texture::Create(1024, 1024); //new size Tex = CamTex2; camera->SetRenderTarget(Tex); After that - a black image :-/ How to decide ? Thanks. Quote Link to comment Share on other sites More sharing options...
MartFayer Posted September 14, 2016 Author Share Posted September 14, 2016 problem solved. CamTex = Texture::Create(CamTexW, CamTexH); camera->SetRenderTarget(CamTex); CamTexMat->SetTexture(CamTex); Quote Link to comment Share on other sites More sharing options...
Genebris Posted September 14, 2016 Share Posted September 14, 2016 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? 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.