OK, I understand, but the thing is I have now removed the glutIdleFunc, and the problem is that if I remove glLoadIdentity() from the drawfunction it works fine, but if I include it, then it does not work…any ideas why this happens?

“then it does not work”
and what happens? consecutive gluLookAt calls will keep multiplying new matrix with old one. glLoadIdentity prevents this. if it doesnt work that your camera isnt moving its because maybe your values are static for gluLookAt and in the other case they get concatenated together. something like that.

i think you didnt understood my post. from the start.

“so why does my program not work when I use glLoadIdentity()?”
because your params to gluLookAt are static! if glLoadIdentity resets the matrix and you give again those values your camera will be at same position as it was.

“As far as I know, glLoadIdentity() simply resets the matrix”
correct. more correct, it sets the matrix to “identity”.

“my gluLookAt works…”
if it works without glLoadIdentity then because you keep “multiplying” the previous lookat matrix with the new one. thus old values are “concatenated” with the old ones and you get the camera movement.

to fix this either do it without glLoadIdentity or add/substract from gluLookAt values on key hit.

“glLoadIdentity() and pushing and popping???”
saves the current matrix with push and restores it later with pop. glLoadIdentity sets it to identity matrix so no transformation takes place.