# 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.

## 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 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 on other sites
Also, when you create your projection matrix, don't set the near plane to 0. The larger the better, but anything over 1 is reasonable.

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 26
• 10
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633717
• Total Posts
3013510
×