Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How to change the size of the texture resolution ?


MartFayer

Recommended Posts

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.

Link to post

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?

Link to post

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Facebook Twitter Youtube Github Steam
×
×
  • Create New...