• Advertisement

Archived

This topic is now archived and is closed to further replies.

Enabling the z buffer

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

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?"

Share this post


Link to post
Share on other sites
Advertisement
wow, i''m blind...

what card are you using? have you tried checking the return value of the SetRenderState?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Hi, try this line:
pDevice->SetRenderState( D3DRS_ZWRITEENABLE , TRUE );

Cirdan

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement