• Advertisement
Sign in to follow this  

z-buffer lost(?) AFTER render to texture

This topic is 4876 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

Hi. I wanted to render a terrain part to a texture, 'cause splatting every frame is really killing me. Texture came just fine. I am doing this: // prepare texture to render to. CDXTexture pTex; hr = g_pDevice->CreateTexture( nTexSize, nTexSize, 0, 3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pTex, NULL); CDXSurface pSurf; hr = pTex->GetSurfaceLevel( 0, &pSurf ); // save the original surface. CDXSurface pOrigSurf; hr = g_pDevice->GetRenderTarget(0, &pOrigSurf); // set the new surface. hr = g_pDevice->SetRenderTarget(0, pSurf); Here I should render something to the texture, and if I do, it works just fine. Let's say I'm not rendering anything, nor setting any other options. I'm restoring the previous seting that way: // restore settings. hr = g_pDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); hr = g_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); hr = g_pDevice->SetRenderTarget(0, pOrigSurf); pOrigSurf->Release(); hr = g_pDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); hr = g_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); Then releasing the texture and so. Absolutely no errors are generated during thios process. Then I'm turning to render my world as usuall. The problem is, it seems that my z-buffer isn't working any more. It's pretty obvious to realize. It's loking exactly like all the z-tests are passed. That is why I try to turn it on before and after changing the surface back to original, but it's not helping. It's turn on, but not working. ANY help appreciated. /def

Share this post


Link to post
Share on other sites
Advertisement
just a guess, when you setrendertartget to your texture,did you CheckDepthStencilMatch ? if the format doesn't match, maybe the depthbuffer already got lost at that time, are you sure the depthtest still working when you rendering the terrian?
after you set the rendertarget back to the orginal buffer, are you expecting the depthbuffer contain the value of the terrain?

Share this post


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

  • Advertisement