Advertisement Jump to content
Sign in to follow this  

about render to texture problem

This topic is 4642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, i get a problem about render to texture.The problem is that i set the D3DXMatrixOrthoLH. hope render from (0,0) to (width,height), and i set the render target dimension as (a*width, a*height). Hope it will render the scene from (0,0,z) to (width,height,z) to a texture with dimension (a*width, a*height). But the texture doesn't just full fill the scene. below is some code:
//imaging this is the render result


|        |    |  
|        |    |  a*height
|        |    |
|---------    |
|             |

the result only render in the small square, not just the a*width and a*height;

D3DXVECTOR3 vecEye(width/2.0f, height/2.0f, 0.0);
D3DXVECTOR3 vecLookAt(width/2.0f, height/2.0f, 1.0);
D3DXVECTOR3 vecUp(0.0f, 1.0f, 0.0f);

D3DXMatrixOrthoLH(&matOrth, width, height, 0, 100);
pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
pD3DDevice->SetTransform(D3DTS_VIEW, &matView);
pD3DDevice->SetTransform(D3DTS_PROJECTION, &matOrth);

//create the render target
pD3DDevice->CreateTexture(width*a,height*a,1,D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pD3DTexture, NULL);

pD3DTexture->GetSurfaceLevel(0, &pTextureSurface);

pD3DDevice->SetRenderTarget(0, pTextureSurface);

//render the scene

//save the texture data


Share this post

Link to post
Share on other sites
I always forget the finer details, but i'm pretty sure the output of the projection matrix will be -1..+1 not 0..+1. Try using D3DXMatrixOrthoOffCenterLH() instead:

The D3DXMatrixOrthoLH function is a special case of the D3DXMatrixOrthoOffCenterLH function. To create the same projection using D3DXMatrixOrthoOffCenterLH, use the following values: l = -w/2, r = w/2, b = -h/2, and t = h/2.

Also, you might want to try configuring the viewport for your new render target. Its not obvious, but there is a final transformation matrix that remaps the 0..1 / -1..+1 projection values to 0..w/0..h screen coordinates.


Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Very thank to your help.
it's seem the viewport problem. but when call setviewport without any error. it didn't work. my texture always be clipped acoording to the current viewport (orgVP). (i have try to call setviewport before and after the settransform func, but it's the same). Now, the result only is correct when the dimension of the current viewport is large than (a*width, a*height).

newVp.MinZ = 0.0f;
newVp.MaxZ = 1.0f;
newVp.X = 0;
newVp.Y = 0;
newVp.Width = width*a;
newVp.Height = height*a;

hresult = pD3DDevice->SetViewport(&newVp);

//set transform and render to target


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!