I am rendering a minigolf course with white walls on the edges:
In my init function I am enabling light, using color tracking to keep colors on polygons and turning on a single light:
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHT0);
In my “light” function I am setting a global light and setting a diffuse light for GL_LIGHT0:
GLfloat global_ambient[] = { 0.4, 0.4, 0.4, 1 };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
GLfloat diffuse[] = { 1, 1, 1, 1 };
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
GLfloat light_position[] = { 1, 1, 1, 1 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
and then I’m drawing the walls:
glBegin( GL_QUADS);
glNormal3f(normal.x, normal.y, normal.z);
glVertex3f(v1.x, v1.y, v1.z);
glVertex3f(v2.x, v2.y, v2.z);
glVertex3f(v3.x, v3.y, v3.z);
glVertex3f(v4.x, v4.y, v4.z);
glEnd();
Where “normal” is the normal vector of the wall and v1-v4 are the vertices of the wall. v1-v4 are given in a counter-clockwise order, when viewing the wall from outside the course.
The problem is that if I try to move the diffuse light away from the course (using the light_position variable), both sides of the wall are lit by this light… I would like it to be just the one side, that is, the one that is facing towards the light. Can you tell me what I am doing wrong?