PDA

View Full Version : Back faces ... Why ?

KurtCob
06-26-2003, 07:03 AM
I´ve put this topic in the begginers forum, but I´ve got no answer, so I´m posting this here. Tnks

Hi guys,
I´m making an aplication that tooks a cloud of points, that have a fixed value in the X coordinate (so it is planar sections) and I want to render this, the first way that I´m trying to implement is to make like this :

| |
|\ |
| \ |
| \|
|-----|
Slice 1 Slice 2

The first triangle is created with 2 points of the slice 1 and one of the slice 2, so I have the vertice A from the slice 1, the vertice B from slice 1 also, the vertice C is from the slice 2, the next triangle (and here I think that is my problem) will be created using the vertice C (slice 2) as A, the next point in slice 2 as vertice B (from slice 2 also), and the vertice B of the first triangle as vertice C, in this way I´m creating one triangle in CW, and another one in CCW, is this why I´m getting back faces ?

If someone wants I can send an ASCII STL file generated with my application.

Hope everybody understood my explanation.
Thank you for the moment
Best regards
Kurt

Relic
06-26-2003, 07:49 AM
Face culling in OpenGL is done with the winding information. Yes, if you have one CW and one CCW order of vertices one of them will be backfacing.
The most effective way to build faces between to partitions is to use triangle or quad strips and the order of the vertices should build a zick-zack image like this:

0 2 4 6
| /| /| /|
|/ |/ |/ | and so on.
1 3 5 7

In a triangle strip each second triangle changes the winding (compare 0_1_2 vs. 1_2_3).
For independent triangles you would need to change the order of each second triangle.

Csiki
06-26-2003, 08:19 AM
Originally posted by Relic:
In a triangle strip each second triangle changes the winding (compare 0_1_2 vs. 1_2_3).

False. See the specification...

KurtCob
06-26-2003, 10:44 AM
Tnks Relic,

But I think you didn´t understand, my object have more than 300 points for each slice, it´s not only two points, and if I work in the way that you said :

|\ |\ |\
|_\|_\|_\

I need to have like this also :

_ _
|\ |\ |
|_\|_\|

Hope you understand what I mean, if a build the next triangle always following the same orientation, it will work, right ?

Thank you for the moment
Best regards
Kurt

By the way, is it a good way of working ? Or am I completly going in the wrong way ?

[This message has been edited by KurtCob (edited 06-26-2003).]

[This message has been edited by KurtCob (edited 06-26-2003).]

dorbie
06-26-2003, 12:17 PM
I don't know that relic was wrong in what he was trying to say, perhaps it was just badly described. I think he was right but not very lucid. 0-1-2 and then 1-2-3 is the vertex order AS SENT for the first two triangles, but winding IS REVERSED on every other triangle so the second triangle's vertex winding order of 1-2-3 becomes 1-3-2, this means that all triangles in the strip face the same way and you get what you're looking for.

Relic's example gives you a solid strip not a sawtooth, he just stripped the edges off his diagram.

KurtCob
06-26-2003, 12:33 PM
Hi guys,
Sorry Relic, I misunderstood your explanation. Now re-reading your post I think I understand, I will try to implement this now.

dorbie, Csiki, Relic, do you want a STL file in order to check if is just this my problem ? I really need help.

Tnks
Kurt

[This message has been edited by KurtCob (edited 06-26-2003).]

KurtCob
06-27-2003, 01:33 AM
Hi guys http://www.opengl.org/discussion_boards/ubb/smile.gif,

I was reading the OpenGL Superbible, but there is one thing I didn´t understand yet, will the winding of my triangles automatic change if I use STRIP triangles ?

2 3
|\ |\
| \ | \
| \| \
0 1 4

The winding will be (0 - 1 - 2) VS (1 - 2 - 3), can I send the triangles following this ? and then OpenGL will automatic do the same winding for all triangles ? Or am I misunderstooding something ?

Rgds
Kurt

Csiki
06-27-2003, 07:39 AM
Originally posted by KurtCob:
Hi guys http://www.opengl.org/discussion_boards/ubb/smile.gif,

I was reading the OpenGL Superbible, but there is one thing I didn´t understand yet, will the winding of my triangles automatic change if I use STRIP triangles ?

2 3
|\ |\
| \ | \
| \| \
0 1 4

The winding will be (0 - 1 - 2) VS (1 - 2 - 3), can I send the triangles following this ? and then OpenGL will automatic do the same winding for all triangles ? Or am I misunderstooding something ?

Rgds
Kurt

Wrong interpretation. http://www.opengl.org/discussion_boards/ubb/smile.gif
It is one thing that what is the order of the vertices you send to the OpenGL, and other that how it renders.

If you send the vertices like: 1, 2, 3 ...
The the rendered triangles will be:
<1, 2, 3>, <3, 2, 4>,
<3, 4, 5>, <5, 4, 6>

Or MSDN: http://www.opengl.org/discussion_boards/ubb/smile.gif

GL_TRIANGLE_STRIP
Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices. For odd n, vertices n, n + 1, and n + 2 define triangle n. For even n, vertices n + 1, n, and n + 2 define triangle n. N – 2 triangles are drawn.

KurtCob
06-30-2003, 02:13 AM
Hi guys,
I know it could be out of topic , but what I need is to calculate my triangles, not how to display it, because my problem is with my STL files, when I tried to load in some diferent applications, I have back faces too, this application recalculate the normals, as my triangles is not with same winding, I got back faces too. Is there an easy way to build all my triangles in CCW, "...By convention, polygons whose vertices appear in counterclockwise order on the screen are called front-facing...", this is the definition that is in the red book. Can someone help me ?

Thank you for the moment
Best regards
Kurt

KurtCob
06-30-2003, 04:09 PM
Do I have a problem without solution ?

jwatte
06-30-2003, 09:37 PM
If you want to know how the entire geometry creation and transformation process works, I suggest a good beginner's guide or tutorial.

If you just want to draw triangles, I suggest turning off back face culling, and drawing all the triangles, using glDisable(GL_CULL_FACE).

rgpc
06-30-2003, 10:58 PM
Sounds to me like you are building your geometry and ending up with faces that are both CW and CCW windings. So when you draw the mesh with face culling on you end up with holes in your geometry (because some of the faces which are supposed to be front facing are actually back facing and get culled).

Is this correct?

If so what you need to do is an alignment of your faces. One way to do that (assuming you have a closed mesh) is to pick a face (lets say.... the first one) and compare the indices for each edge against the indices for the adjacent tris. The order of the indices for the two tris that share an edge should be opposite - if they are not then switch the winding on the "other" tri and continue. You will probably have to store a flag to indicate which tris you have checked/corrected and you might have to do multiple passes to get it all right.

So if you have two tris with indices (0, 1, 2) and (1, 2, 3) you would be comparing the indices for the edge (1, 2) - which is the shared edge. Because they are in the same order (ie. 1 then 2) they can be considered to have opposite winding - so you need to change the second tri to (3, 2, 1).

Of course if this is not what you are asking then use jwatte's suggestion and turn face culling off.