about render to texture problem

Started by
1 comment, last by GameDev.net 17 years, 11 months ago
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*width)->|

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

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


//view
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);
D3DXMatrixLookAtLH(&matView,&vecEye,&vecLookAt,&vecUp);

//prjection
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
.............


allien.
Advertisement
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:

Quote: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.

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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).


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

pD3DDevice->GetViewport(&orgVp);
hresult = pD3DDevice->SetViewport(&newVp);

//set transform and render to target
....



allien.

This topic is closed to new replies.

Advertisement