more gluLookAt difficulties

I am using GLUT, trying to switch between two camera locations. Here is my keypress handler:

/* Keypress handler */
void mainKeys(unsigned char key, int mouseX, int mouseY){
glLoadIdentity();
switch(key){

case 27:
case ‘3’:
exit(0);
break;

case ‘1’:
glLoadIdentity();
gluLookAt(0,0,5, 0,0,1, 0,1,0);
glutSwapBuffers();

break;

case ‘2’:
glLoadIdentity();
gluLookAt(4,3,2, 0,0,1, 0,1,0);
glutSwapBuffers();

break;

}
}

When I push ‘1’ or ‘2’, nothing happens. When I push ‘3’, the program exits as expected. Am I thinking about this wrong? Is there a certain context to call gluLookAt()?

Thanks for helping me learn.

P-Sz

First I see that you are calling glLoadIdentity twice, get rid of the one before the switch statment.
Also get rid of the glutSwapBuffers()statments and use it only at the end of your drawing routine.

I would have to see more of the program to see what else is going on.

Originally posted by PSzalapski:
[b]I am using GLUT, trying to switch between two camera locations. Here is my keypress handler:

/* Keypress handler */
void mainKeys(unsigned char key, int mouseX, int mouseY){
glLoadIdentity();
switch(key){

case 27:
case ‘3’:
exit(0);
break;

case ‘1’:
glLoadIdentity();
gluLookAt(0,0,5, 0,0,1, 0,1,0);
glutSwapBuffers();

break;

case ‘2’:
glLoadIdentity();
gluLookAt(4,3,2, 0,0,1, 0,1,0);
glutSwapBuffers();

break;

}
}

When I push ‘1’ or ‘2’, nothing happens. When I push ‘3’, the program exits as expected. Am I thinking about this wrong? Is there a certain context to call gluLookAt()?

Thanks for helping me learn.

P-Sz[/b]

You should also call gluPostRedisplay in the end of you keyboard function to tell GLUT you want to update your window. If you don’t do that, you won’t see any changes cause you don’t draw anything new.

Originally posted by Bob:
You should also call gluPostRedisplay in the end of you keyboard function to tell GLUT you want to update your window. If you don’t do that, you won’t see any changes cause you don’t draw anything new.

Thanks, that worked (glutPostRedisplay).

P-Sz