Sign in to follow this  
CDProp

z-Buffer in wireframe mode [solved]

Recommended Posts

CDProp    1451
Hey guys, I was just wondering how the z-buffer worked in wireframe mode. I'm trying to complete a tutorial I'm reading from Frank Luna's book, in which I am to draw a unit cube with 12 triangles in wireframe mode. I am writing the code myself based on what I'm learning in the book, as opposed to copying his source code precisely. I noticed something peculiar. In my version, it seems as though some of the polygons are solid while others aren't (see screen shot below). It's almost as if the polygons are drawn in a somewhat random order, and even though the polygons are empty (invisible, so to speak), their depth data is being written anyway, so depending on which polygons were drawn first, some times you can see the polygon edges that would be obscured by foreground polygons and sometimes you can't. That's my theory anyway. It didn't really pan out, though, because I tried turning z-Buffering off like so: g_pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); However that didn't have any effect. In the book, the screen shot clearly shows ALL of the "wires"...on back faces as well as front faces, even when one face obscures another. I tried looking at his source code to see what I did wrong, but I can't seem to find any important difference. So, I tried compiling and running his source code myself, and here's the interesting bit, on my machine his source code doesn't show any of the backface wires at all: Does anyone know why this happens? EDit: I apologize if the picture doesn't work. It seems to work in the preview, but not in the thread itself. Here is the URL: http://i67.photobucket.com/albums/h298/cdesign_proponentist/wire2.gif Edit2: Some more notes: 1. I couldn't help but notice that the source code in the book was different than the actual source files, particularly that a FVF was used in the source files downloaded from the website whereas I (and the code in the book) use vertex declarations. There might be some other differences that I could check out. 2. The demo shows the cube from multiple angles, and so I am able to determine that the verts have the correct position and the index buffer is properly referencing them to build the triangles...all of the triangles look correct if they're being obscured by any of the other triangles. [Edited by - CDProp on February 29, 2008 5:02:08 PM]

Share this post


Link to post
Share on other sites
ibebrett    205
When drawing triangles most of the time you do a front facing test where you check if the triangles normal is pointing towards the camera. If its not, its not drawn. Look up how to turn off this check. it is called back face culling.

(this is only my guess)

Share this post


Link to post
Share on other sites
CDProp    1451
I thought that might be it, but it looks like a couple of those poly edges its drawing are from faces that are clearly pointing away from the camera. Maybe my winding order is messed up. I'll look into that, thanks.

EDit: Nope, it still does it even though I turned backface culling off. Good suggestion, though; ++rating

Edit2: No, actually you were right. I set the wrong state, lol. Thanks again!

Edit: I've reordered a couple of the triangles, and the result looks great:



[Edited by - CDProp on February 29, 2008 5:56:54 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this