Hello, I’m currently experimenting with OpenGL in combination with SDL.
My problem:
As the camera rotates, the way the terrain is being lighted changes completely, as if the camera transformation is being taken into account during the lighting calculation.
I guess that the problem lies in the order I’m applying my matrices. This is my rendering code (simplified form):
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective(45, 800.f / 500.f, 1, 1000);
//Initialize Modelview Matrix
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
gluLookAt(position.getX(),position.getY(),position.getZ(),
lookAtPosition.getX(),lookAtPosition.getY(),lookAtPosition.getZ(),
upDirection.getX(),upDirection.getY(),upDirection.getZ());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Draw all the stuff in the world
for (vector<Entity*>::iterator itr=entityManager->entities.begin(); itr != entityManager->entities.end();itr++){
(*itr)->render();
}