Jump to content
  • Advertisement
Sign in to follow this  
turd7000

VertexBuffer overlap

This topic is 4336 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
Advertisement
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.

Admiral

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!