My application produces a list of triangles. all my triangles are wound counter clockwise yet somehow some of my triangles simply disappear.
I tried to create two triangles from the original and swap 0,1,2 for 2,1,0
Then i see that some of my triangles are green and others are red.
So i’m pretty sure for some reason some of my triangles are not wound properly.
Assuming I know the center of the object being rendered from all these triangles, is there any way to use the face normal to identify which triangle is wound incorrectly?
have a look at glEnable && glCullFace at
For a manifold surface with consistent winding, every edge will either occur once (if it’s part of the boundary of an open surface) or twice (if it’s an interior edge). In the latter case, the two occurrences will always have opposite direction, i.e. if one edge runs from vertex A to vertex B, the other will run from B to A. If both occurrences have the same direction, then the two faces which share that edge have inconsistent winding.
For a closed surface, a line segment from any point inside the surface to any point outside the surface will intersect the surface an odd number of times. If the number of intersections is 2N+1, there will be N+1 intersections where the outward face normal is in the same direction as the line segment (positive dot product) and N intersections where the outward face normal is in the opposite direction (negative dot product). This allows you to determine whether consistently-generated face normals point inside or outside.
For a triangle with vertices a,b,c in that order, if the normal (b-a)×(c-a) points toward the viewpoint then the winding is anti-clockwise.
You appear to be describing a polygon interior test.
Towards the viewpoint?
I am rending a sphere or a cube as a test… tumbling.
Nice reply thank you!
Indeed that is what i used, in fact this is pretty much the whole init…
I’m not using triangle_strip, i am using triangles
for each t in mTriangles
for i=0 to 2
OpenGL.glColor3f(t.c.Red/255.0, t.c.Green/255.0, t.c.Blue/255.0)
OpenGL.glNormal3f(t.norm.x, t.norm.y, t.norm.z)