Lighting Problem

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

-4.0 1.0 -4.0 0.0 1.0
-1.0 1.0 -4.0 1.0 1.0
-1.0 0.0 -4.0 1.0 0.0

My question is. How to make the lighting works properly in the back?

A wall with non-zero thickness is made of 6 rectangles, not just 1.

If really you want to stay with 1 rectangle per wall, you have to play with two-sided lighting and disable backface culling.

Search for “two-sided” on each of these pages :
http://glprogramming.com/red/chapter05.html
http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html

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.

Ok thanks. I’ll try it out.

Thanks again.