Hello, I have a problem with lighting in OpenGL, when I rotate camera changes the illumination of the scene.
The light is directional: incident at the same angle for all objects, like the sun.
const GLfloat lightAmbient[] = {0.2, 0.2, 0.2, 1.0};
const GLfloat lightDiffuse[] = {1.0, 0.6, 0.0, 1.0};
const GLfloat matAmbient[] = {0.6, 0.6, 0.6, 1.0};
const GLfloat matDiffuse[] = {1.0, 1.0, 1.0, 1.0};
const GLfloat matSpecular[] = {1.0, 1.0, 1.0, 1.0};
const GLfloat lightPosition[] = {0.0, 0.0, 1.0, 0.0};
const GLfloat lightShininess = 100.0;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matSpecular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, lightShininess);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
I tried calling glLightfv on each frame after tell opengl which is the matrix of the camera, but still happening:
glMatrixMode(GL_MODELVIEW);
float mat[4*4]={ CamMatrix->iM[0], CamMatrix->iM[4], -CamMatrix->iM[ 8], 0,
CamMatrix->iM[1], CamMatrix->iM[5], -CamMatrix->iM[ 9], 0,
CamMatrix->iM[2], CamMatrix->iM[6], -CamMatrix->iM[10], 0,
CamMatrix->iM[3], CamMatrix->iM[7], -CamMatrix->iM[11], 1 };
glLoadMatrixf( mat );
glPushMatrix();
float lightPosition[] = {0.0f, 2.0f, 1.0f, 0.0f};
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
Thanks in advance.