I have a new problem. My scene is a cube missing one face so we can see inside. There's a light source inside the cube, and we can see that the faces are lit inside the cube, and dark outside the cube, as we want to.
http://img504.imageshack.us/img504/2163/50698191.png
However, I also have a light source on the outside of the cube. In theory, it should light up some of the exterior faces of the cube, but it does weird things. Some faces are lit up inside the cube, some faces just don't lit up at all. The same lighting seems applied on both sides of the same face. It's behaving in a completely different way.
On this screenshot, the light source is in the upper-right corner, the specular highlight on the sphere tells approximately in what direction it is. It is outside of the cube completely.
http://img441.imageshack.us/img441/2426/44598075.png
I would expect the faces facing the light to be lit up, but they are dark, and some of the faces on the opposite side of the cube are lit. Also if I rotate the cube I can see the same lighting is applied on both sides of each face.
Here is some of my code.
I use a material for the red cube defined as so:
GLfloat red_ambient[] = { 0.2f, 0.1f, 0.1f, 1.0f }; GLfloat red_diffuse[] = { 1.0f, 0.0f, 0.0f, 1.0f }; GLfloat red_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glNewList(RED_MAT, GL_COMPILE); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, red_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, red_specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 64.0); glEndList();
And the bogus light is defined as such : global variable
GLfloat positionLight1[] = { -10.0f, 0.0f, 10.0f, 0.0f };
Initialization:
GLfloat light_ambient[] = { 0.5f, 0.5f, 0.5f }; GLfloat light_diffuse[] = { 0.5f, 0.5f, 0.5f }; GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
And that's basically it. Here are the general GL calls in the init function:
glShadeModel(GL_SMOOTH); glClearColor(0.0, 0.0, 0.0, 1.0); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);