PDA

View Full Version : Backface culling



08-11-2000, 03:50 PM
on the internet I found this about backface culling:

We need to do the following steps:

1) Transform the camera position into object space

2) For every face in object:

2.1) Make a vector from the camera to a point on the face (a vertex)
2.2) Perform dot produce on this vector with the face normal
2.3) If dot product result is greater than 0, face is visable.
If dot product result is 0, face is side on.
If dot product result is less than 0, face is hidden.

But... how do you send only once face and not the other? I mean when we send 3 verticies by glBegin(GL_TRIANGLES), we give it the option of drawing it with both faces... how do I implement this? and should I implement this or leave it to glEnable(GL_CULL_FACE); ??

drakaza
08-12-2000, 01:53 AM
I am not sure I understand what you mean...

You do your backface tests. If a face is hidden, do not do the glBegin() call at all. If it is visible, use glBegin().

You can then disable GL_CULL_FACE because you are doing your own backface culling.

Is this what you meant?

[This message has been edited by drakaza (edited 08-12-2000).]

Relic
08-12-2000, 08:49 AM
>>>and should I implement this or leave it to glEnable(GL_CULL_FACE); ??

Your method is useful when you don't care for the winding order of the triangles.

OpenGL relies on the winding order to determine the front face (and therefore the correct lighting).

If you know the winding order for all triangles (default GL_CCW) leave the culling to the OpenGL implementation.