FRONT BACK

I now have a plane that is red, and I have lights on it. One sid is red and the otherone is dark, front and back.

The thing is…it doesn’t change when I change from counterclockwise to clockwise, the front is still red…

shouldn’t clockwise vertex placment make the back face the viewer?

you are using only glCullFace, not glFrontFace?

For lighting purposes, the winding of polygons has no influence. The front side is determined by the normals you define.

yes, but if I don’t difine a normal it is the same way!

just curious, if the normals define the front side, how about this:

two vertex-normals of a quad point to the orther direction compared to the other two, now we define the front color to be red and the backside to be green:


glMaterialfv(GL_FRONT, GL_DIFFUSE, red, 0);
glMaterialfv(GL_BACK, GL_DIFFUSE, green, 0);

glBedin(GL_QUADS);
glNormal3f(0,1,0);
glVertex3f(..);
glVertex3f(..);
glNormal3f(0,-1,0);
glVertex3f(..);
glVertex3f(..);
glEnd();

how das OpenGL know which side is the front and therefore use the red color?
I thought glFrontFace is used, but maybe I’m wrong… :-\

hehe, same thought then mine :slight_smile:

Hmm, I admit my explanation was a bit confusing.
glFrontFace and the winding of primitves is important for backface culling and determining the material of a vertex (cfr. glLightModel, GL_LIGHT_MODEL_TWO_SIDE, glCullFace, glMaterial).
For lighting calculations however the normals are used to calculate how light reflects off of the primitves you defined.
Assume the following situation:

  • One quad (0,0,0), (1,0,0), (1,1,0), (0,1,0) with a normal (0, 0, 1)
  • A directional light with direction (0, 0, -1)
    In the case of single sided lighting, this means that one side of the quad will always be lit and the other side will be dark, regardless of the winding of the quad. If two sided lighting is enabled, OpenGL will invert the normal for you and use that to perform lighting calculations.

In the situation you describe (opposite facing normals), the quad will be half lit, half dark. This happens because the fixed OpenGL pipeline performs lighting calculations on a per vertex basis. Two of the vertices will be lit, the two others will be dark. Then depending on the shading model you’re using the interior of the quad will be interpolated or use a single color (smooth or flat respectively).

I’ve attached some images that show the effects of all this stuff using the geometry listed below. The images show flat shading, single sided lighting and two sided lighting. The white lines show the normals for each vertex.

glBegin(GL_QUADS);
glNormal3f(0,0,1);
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glNormal3f(0,0,-1);
glVertex3f(1, 1, 0);
glVertex3f(0, 1, 0);
glEnd();