Archived

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

Depth Sorting / Testing

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

This is insano newb question I know but the answer still evades me... I''ve only just begun using Direct3D and I''m running into some rendering issues with displaying the scene correctly sorted. The app I''m working on is just a demo-ish program I''m fiddling with to try to learn more about DX. Basically I initialize everything, create some geometry in code(just a cylinder). The code is not optimized in any fashion, in fact it is a tri-list, not a strip just to keep the thinking factor as low as possible for such a "bs" testing app. Anyway, during the render it is displaying the triangles incorrectly in that it does not sort them by depth. I''ve been reading through the documentation and the book that I am learning from and both say that depth testing in DX are enabled by default. It seems that it is not testing each vertex/pixel against the depth buffer, which results in whichever triangle is next in the buffer is what will be considered "on top" and draw over any tri that is previously drawn. Do I have to explicitly call something to force it to do so or do I need to implement my own sorting algo.? The latter seems fairly foolish since this sort of thing will need to be done in virtually every single application, which makes me think that I''m just not using the API correctly. --Thx in advance for any help/assistance you can provide.

Share this post


Link to post
Share on other sites
Not sure if this is what you''re looking for.

I believe that you have to SetRenederState to D3DRS_ZENABLE , TRUE.

something like g_device->SetRenederState(D3DRS_ZENABLE ,TRUE);
before you render.

You might want to search for the exact syntax, since I''m getting this off the top of my head.

Share this post


Link to post
Share on other sites
I know what you''re talkin about and that APPARENTLY isn''t it. Yes I have fiddled with the Z-enable render state and it doesn''t seem to cause _ANY_ change to the execution. Triangles that are "in the back" will still render on top of the "front" ones. Exactly which triangle is drawn in front is currently only being affected by the order in which they are sent to the vertex buffer. That''s why I''m wondering if I have to process them before hand to sort them by their Z value so that they''ll be in the right order in the buffer.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
make sure auto depth stencil is set to true in the present parameters when creaing the d3d device
make sure you also set the format

Share this post


Link to post
Share on other sites
I think perhaps I''ve totally misunderstood exactly what the stencil buffer is/does. Could you perhaps give a brief descrip?

M0RBIUS <- newbie and knows it
M0RBIUS <- thanks everybody for helping

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You may just have screwed up the culling order. Try changing between D3DRS_CULLMODE = D3DCULL_CW and D3DCULL_CCW.

You don''t need stencil, but you do need a depth/stencil buffer. They share the same block of RAM (different bits of a DWORD), but you only care about the depth part for now.

When you are creating your device, in the d3dpp (Presentation Parameters), you should tell DirectX to make you a depth buffer. If you don''t, ZEnable won''t work. You''ll want something like this:

d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8;

Share this post


Link to post
Share on other sites