I have a 3D maze right now and I want to add some lighting. But I can’t get it work correctly. The front of the wall is lighted correctly but when I went to its back it’s not…
Lighting in X works fine
O
XXXXXXXXXXXXXXXXXX
Lighting in X doesn’t work
XXXXXXXXXXXXXXXXXX
O
Where: X = wall
0 = camera
Here’s the coordinates.
glNormal3f( 0.0f, 0.0f, 1.0f);
Wall
X Y Z Texture coordinates
-4.0 1.0 -4.0 0.0 1.0
-4.0 0.0 -4.0 0.0 0.0
-1.0 0.0 -4.0 1.0 0.0
If you want a polygon to be visible from either side and also properly lit, do this:
// in your GL init code:
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); // ensures proper lighting for two-sided polygons
// in your scene draw code:
glDisable(GL_CULL_FACE); // disable backface culling so both sides of the wall are visible
// draw polygons
glEnable(GL_CULL_FACE); // enable backface culling again for other geometry
FYI: GL_LIGHT_MODEL_TWO_SIDE really just tells the GL renderer to invert the glNormal when it draws the back facing pixels.