This topic is 3646 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello All, I wasn't sure if I should put this in the beginners forum or this one, but it is specific to Direct3D so here it is. I have been following the SDK tutorials online through the MSDN site and trying to follow along. And now I got past the tutorial on "Rendering Vertices", and I had a strange issue come up that I don't understand. When setting up the D3DPRESENT_PARAMETERS parameters, there is a property called: EnableAutoDepthStencil that I had set to true (from another online article), and when I ran the application, I got the triangle rendered with missing colors and it looked completly wrong. But I then set the EnableAutoDepthStencil property to false, and it fixed the issue, the triangle rendered fine. Can someone please try to explain this property to me? I have done some googling on the topic, but its confusing me. Thanks a lot Mark

##### Share on other sites
It can be a few things, it would help me if I could see your code. I'll try a wild guess though.
Now that EnableAutoDepthStencil is TRUE, you have a depth stencil. Therefore you need to clear it every frame, which you possibly don't.

Your Clear() call should look like

pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 0.0f, 0);

Setting EnableAutoDepthStencil to true just asks the device to create a depth buffer (used to store depth values) with the swap chain (back buffer / front buffer, used for storing color values)

Google up "depth buffer" or "z-buffer" ;)

##### Share on other sites
Firstly, thanks for the prompt reply. You were right, with the extra flags in the clear method, it fixed the issue. I understand that it needs to be clear each frame, but I don't understand why.

I'll do a Google on the topics you mentioned too, thanks.

##### Share on other sites
Right, google up some in depth (no pun intended!) explanations as depth buffering is one of the most important concept of 3D rendering for games. Here's a simple explanation to get you started.

When you render 2 triangles, you want the one in front to actually appear in front of the other regardless of the order you render them (for example, render the one in front first, and the one in back then) For this to happen correctly, the GPU needs a way to tell who is in front of who. This occurs on a per pixel level. Basically, every time the GPU ouputs a pixel, it stores it's depth at the same time (in the depth buffer!), so that subsequent pixel writes at the same coordinate will be rejected if their depth is greater (meaning that they are behind, thus not visible)

Now, you can understand easily why it is important to clear the depth between each frame. If you don't, the depth value of the previous frame are still in the depth buffer, preventing some pixels frome being writen. (in an ideal world with perfect precision though, you wouldn't see artifacts like you described. The outputed depth would be exactly the same as on the previous frame and your triangle would be either visible or invisible, depending on the gpu using a "greater" or a "greater or equal" comparison method)

Hope this helps
-JA