View Full Version : Debug/Feedback Backface Culling

05-31-2009, 09:50 AM
Hi all,
I just entered openGL.
And already run into problems ;-).
For geometric calculations, I need information about triangles that are culled.
I tried program the culling myself but it somehow does not match with the culling of opengl.
See image: http://img268.imageshack.us/img268/7425/cullingproblem.jpg (this is the inner side of a head. i asked opengl to cull the front faces away)
OpenGL and my calculations are not the same. I colored the triangles according to my culling test, and basically, all triangles should be red but some are not). So I was wondering how I can debug/reproduce openGL's calculations. From the outcome, I think openGL's results are correct.
In the code, there is a
gluLookAt(x, y, z,
x + lx,y + ly,z + lz,
I then used the lx,ly, lz vector and multiplied it with the computed normal vector of my triangles (or the vertices, that i pushed into openGL during drawing).
What might be wrong?
The culling operation itself is not so hard, so I wonder what might be the error. Maybe I cannot use lx,ly,lz as a view vector?
Would be super if someone could help, it is for a freeware tool!

Ilian Dinev
05-31-2009, 10:19 AM
Multiply the triangle's vertices by the final model-view-projection matrix ( = projection * model_view) . To find if a triangle should be culled, find the cross-product of two of its edges. If z is negative (or positive, I don't remember), then the triangle is culled. That's the way gpus decide whether to cull, afaik.

06-01-2009, 07:01 AM
Hi Ilian,
i implemented your suggestion and it seems that you were correct. Applying the transformation to the vertexes resulted in equivalent culling. I think I need more knowledge of the mathematical fundamentals. Appearently,the perspective transformations do not leave the triangle orientation invariant. Which I thought it must, as the matrices seemed linear/affine transformations.
Either way, thanks a lot.
I now have a point for doing research.