SetDepthStencilSurface() doesn't work!

Started by
1 comment, last by Christoph 18 years ago
Hi all, I'm currently trying to let some water flow, but already at the point of reflection I had to rummage in forums for hours... Now I see myself forced to tell you my problem. Look at this code:

LPDIRECT3DSURFACE9 oldDepthStencil, newDepthStencil;
device->GetDepthStencilSurface(&oldDepthStencil);
device->GetRenderTarget(0,&(waterEffect->backbuffer));

device->CreateDepthStencilSurface(128*waterEffect->quality,128*waterEffect->quality,D3DFMT_D24S8,D3DMULTISAMPLE_NONE,0,TRUE,&newDepthStencil,NULL);
device->SetDepthStencilSurface(newDepthStencil);	
device->SetRenderTarget(0,waterEffect->projSurface);
device->Clear(0,NULL,D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,0,255),1.0f,0);

// draw scene objects
			
device->SetDepthStencilSurface(oldDepthStencil);
device->SetRenderTarget(0,waterEffect->backbuffer);

D3DXSaveTextureToFile("tmp.bmp",D3DXIFF_BMP,waterEffect->projTexture,0);

As you can see, I check the texture I render to by saving it to disc. Here, I can clearly see that NO Z-Buffer is applied at all (meaning newDepthStencil is ineffective). Z-Buffering is enabled by RenderState, I have tried thousands of formats for my DepthStencil-Surface and the "normal" Z-Buffer oldDepthStencil works fine... So do you know what I'm doing wrong? Thanks a lot!!
Advertisement
(1) You aren't checking the result codes of any of the IDirect3DDevice9 functions. These functions could be returning failure, but you don't know since you don't check. For example:

if( FAILED( device->CreateDepthStencilSurface( blah blah blah ) ) ){   // Error handling code}


(2) Have you checked the debug output for helpful messages the debug runtime may be giving you? If you don't know what this is or how to use it, check the forum FAQ.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
damn, you're right, CreateDepthStencilSurface throws an exception!
I must know why...
Thank you!

This topic is closed to new replies.

Advertisement