Define which triangle is visible?

Hi
I have a set of triangles, forming e.g a cube. I want to do a special treatment on the visible triangles (it mean triangle for wich i see the front face (and not the backface). I’m not talking about z value but about the face orientation.
How can I do it?
Thanks

If all you want to do is render them in a
different way, then you can just call
glCullFace(GL_BACK) and draw your front facing
polygons however you wish, then call
glCullFace(GL_FRONT) and draw the backfacing ones
the other way.

if you need to know which ones are facing forward
you can test the eye point against the plane
equation of the polygon to see if the eye point
lies in front of or behind the polygon.

you will need to transform your eye point by the
inverse of the modelview matrix of the polygon.

this is used a good deal in stencil shadow volumes
or silhouette edge detection -

this link should help you:
http://www.paulsprojects.net/opengl/shadvol/shadvol.html

To know if a face is fronting the view, simply use its normal and compare it the the normal of the view plane (eg Vector center-eye from LookAt).

Originally posted by Aeluned:
If all you want to do is render them in a
different way, then you can just call
glCullFace(GL_BACK) and draw your front facing
polygons however you wish, then call
glCullFace(GL_FRONT) and draw the backfacing ones
the other way.

No, I don’t want to render them. I just have to compute values using the front faces. It mean, having an array of quad(or triangles), I have to keep only the quad(or triangles) being a front face.

Originally posted by jide:
To know if a face is fronting the view, simply use its normal and compare it the the normal of the view plane (eg Vector center-eye from LookAt).
Ok. But do I have to do it manually, testing the angle between the normal and my “vector of view” (using a dot product)? Or is there a function looking like: boolean isFrontface(int[] normal) ?

the object may have undergone some transformations
though…don’t forget to take that into account.

if you’re just going to use the normal make sure
you transform the normal before the comparison.

The normal matrix I believe is derived from the
upper 2x2 square matrix of the inverse modelview.
I don’t know why you would want to transform so
many normals when you could just transform 1 point
though.

EDIT: p.s. no, there is no such function and yes,
you would use the dot product.