Jump to content
  • Advertisement
Sign in to follow this  

VertexBuffer overlap

This topic is 4257 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 drawing two cubes both made of vertexbuffers, but when I rotate the camera to a certain position, the second cube(which is positioned behind the first cube) renders over the first cube. This is because I draw it second. I've heard there is some way to get DirectX to automatically handle this problem, something about the ZBuffer? I've tried searching but no luck. Thanks in advance for any help.

Share this post

Link to post
Share on other sites
MSDN has details, but to get depth-testing working, you need to do very little:

Create the device with a valid depth-buffer format:
<D3DPRESENT_PARAMETERS>.AutoDepthStencilFormat = D3DFMT_D16;
<D3DPRESENT_PARAMETERS>.EnableAutoDepthStencil = true;
Set the render-state prior to rendering. You need not do this every frame unless you need to disable it at any point:
<IDirect3DDevice9>.SetRenderState(D3DRS_ZENABLE, true);
Clear the z-buffer along with the render target, at the beginning of each render cycle:
<IDirect3DDevice9>->Clear(..., D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, ...);
This should get you going. Not to sound rude, but this question would probably have been more appropriate in the For Beginners forum.


Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!