PDA

View Full Version : Does GL_CULL_FACE uses normals???



KRONOS
07-17-2000, 05:11 AM
The thing is that I have a scene full of cubes and to draw then I use triangle strips
But then I activate culling and the half of the faces dissapear because drawing a QUAD using TRIANGLE_STRIPS makes de first triangle front facing and the second back facing or vice_versa. HELP me.......... How can I solve this problem, normals don't seem to change the CULL_FACE so I can I do it?

MikeC
07-17-2000, 06:06 AM
No, you don't need normals. You're just issuing your vertices in the wrong order.

ribblem
07-17-2000, 11:05 AM
Just to clarify MiceC's answer it is the ordering. Looking at triangle you can either order the vertices such that they are in a clockwise or counter clockwise order. By default opengl uses counter clockwise as front facing. The call to change the front facing winding order is:

glFrontFace(); which takes either GL_CCW or GL_CW

MikeC
07-17-2000, 12:47 PM
Um... actually, no, that's not what I meant. Sorry, I should have been clearer. KRONOS says that half of his triangles are appearing correctly, so his problem isn't his winding order setting, it's the order in which he's issuing his vertices. Specifically, you have to issue the same 4 verts in different orders for GL_QUADS and GL_TRIANGLE_STRIP modes.

Say your verts look like this, and you want counterclockwise faces to be "front" - this is the default.




1---4
| |
2---3


In GL_QUADS mode, quad N (starting from 1) is specified by verts {4N-3,4N-2,4N-1,4N} in that order. So in our setup quad 1 maps to verts {1,2,3,4}. This is counterclockwise so the quad is frontfacing.

In GL_TRIANGLE_STRIP mode, it's a different story. An ODD triangle N is defined by verts {N,N+1,N+2}. So our triangle 1 maps to {1,2,3}, which is counterclockwise so we're OK. But an EVEN triangle N is defined by verts {N+1,N,N+2}. Our triangle 2 maps to {3,2,4}, which is CLOCKWISE. Oops. Every other triangle is facing the wrong way.

Solution: for GL_TRIANGLE_STRIP, arrange your vertices like this instead :




1---3
| |
2---4


and everything will be fine.

Hope that's a bit more helpful.


The message brought to you by MiceC, the preferred programming language of small rodents everywhere.

KRONOS
07-17-2000, 11:15 PM
thank MikeC
the problem was I thought TRIANGLE_STRIPS were drawn like this {1,2,3,4} the triangles were (1,2,3) and (2,3,4) so this way you could never get it right!!