Enabling the z buffer

Started by
7 comments, last by rileyriley 22 years, 2 months ago
I''m using DX 8.1, and having a lot of difficulty getting the z buffer to mask polygons correctly. As of right now, all I''m doing to enable z buffering is:
  	d3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
	d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f ,0);
	d3dDevice->BeginScene();  
Then I go on to draw two tetrahedrons, using two vertex buffers. Even though (I think) z buffering is enabled, the polygons that I draw last get drawn on top of the first polygons, even when they are farther away from the ''camera''. Am I missing some step, like enabling z buffering for each polygon I draw, or something? In open GL you just enable zbuffering and it''s done - I assumed it was the same in DX, but I could be wrong. Thanks for any help - Riley ps - I know this has probably been answered before, but I''ve exhausted the SDK docs and the search function for gamedev seems to be down. Does anyone else get "query contains only ignored words?"
--Riley
Advertisement
Did you SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE) ?
Yes - it''s that first line I posted above.

Thanks, and thanks for any future replies -
Riley
--Riley
wow, i''m blind...

what card are you using? have you tried checking the return value of the SetRenderState?
mistake mde by most ppl (including me), check to see which direction the z buffer is going. (ie is greater z mean closer to viewer or not? i forget the default, its in the docs). also check your projection matrix, possible the vaules are to close or far away form each other (though i doubt this since your polys are being drawn).

also did you enable auto depth buffering when you created the device? if not you will need to create a depth buffer for your device or you wont get z buffer no matter how many times you trun it on.
Hmm, I haven''t enabled auto buffering, I think. I''ll try that when I get home.
--Riley
Hi, try this line:
pDevice->SetRenderState( D3DRS_ZWRITEENABLE , TRUE );

Cirdan
Yeah, you need to set the EnableAutoDepthStencil member of your presentation parameters structure to TRUE and the AutoDepthStencilFormat member to D3DFMT_D16, D3DFMT_D32, etc.
Ok, I just hadn''t set my presentation parameters correctly. Thanks for the help! Works fine now.
--Riley

This topic is closed to new replies.

Advertisement