Hi,

I want to create an openGL program where a fixed light source shines on a rotating cube. The problem is that the cube is not light up correctly.
Different sides of the cube seem to light up randomly as the cube rotates instead.

The cube is placed at position x,y = 1.0 and z = -10.0 using glTranslate. Then it is rotated 45 degress on each axis using glRotate.

The light source is placed at position 1.0,1.0,-5.0. So that it shines right onto the cube. White is used for ambient light while red is used for diffuse light.
glLightfv(GL_LIGHT0,GL_POSITION,lightDir); is used to position the light.
glLightfv(GL_LIGHT0,GL_AMBIENT,white); is used for ambient light.

Then i enabled the light source using glEnable.
glEnable(GL_LIGHTING); glEnable(GL_LIGHT0);

For the normals I used a normal which is perpendicular to each side of the cube.

For the front and back face,the normal is along the z axis.
glNormal3f(0.0,0.0,1.0); for front face and glNormal3f(0.0f,0.0f,1.0f); for back face.

For the left and right face, the normal is along the x axis.
glNormal3f(1.0f,0.0f,0.0f); for left and glNormal3f(-1.0f,0.0f,0.0f); for the right.

For the top and bottom face, the normal is along the y axis.
glNormal3f(0.0f,1.0f,0.0f); for the top and glNormal3f(0.0f,-1.0f,0.0f); for the bottom.

Is it the normals which is giving the problem? The rotating cube appears correctly but the lighting isnt applied correctly.