iDevGames Forums
OpenGL gluLookAt() not doing anything? - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenGL gluLookAt() not doing anything? (/thread-2660.html)

OpenGL gluLookAt() not doing anything? - ene777 - Apr 25, 2008 04:59 PM

Ok I am brand new to openGL so I Know I am doing something wrong here! Basically I have 3 spheres drawn, one is out of the screen, this is exactly what I want. But I want the user to be able to change camera position so his looking from negative 10 on the x-axis, this will allow him to see the 3rd sphere... however i try doing this when the user hits #2 with a key event, and nothing happens. I have a feeling I am not using matrices correctly, here is my code... the asterisk (*) is where the problem is
Thank you for any help you can give!!!!

using namespace std;

void handleKeypress(unsigned char key, int x, int y)
case 'q':
case 27:
case 'a':;
    //start animation
case '1':;

case '2':
//*************this does nothing!*************
//change camera to view 2
gluLookAt(-10.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

void initRendering()
    glEnable(GL_DEPTH_TEST); //make 3d work when something is in front of it

void drawScene()
    //clear the screen from last draw
  // draw something
gluPerspective(45.0, 600 / 600, 1.0, 100.0);

gluLookAt(0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    glTranslatef(0.7, 0.0, 0.0);
    glColor3f(1,1,1);//Change the object color to white
    glutSolidSphere(.1, 600, 600);

    glColor3f(0,0,1);//Change the object color to blue
    glutSolidSphere(.4, 600, 600);

    glTranslatef(40.0, 0.0, -5.0);
    glColor3f(1,1,0);//Change the object color to yellow
    glutSolidSphere(5.0, 600, 600);


void main(int argc, char** argv)
//init GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE |GLUT_RGB |GLUT_DEPTH);

    glutInitWindowSize(600, 600); //set window size
    glutInitWindowPosition(100, 100);
    glutCreateWindow("Project 3");

    //set handler functions for drawing, keypresses, and window resizes
//    glutReshapeFunc(handleResize);

// define the color we use to clearscreen

    glutMainLoop(); //start the main loop

OpenGL gluLookAt() not doing anything? - ThemsAllTook - May 1, 2008 08:50 AM

I see two problems here:
  • You'll need to call glutPostRedisplay at the end of handleKeypress so that your displayFunc will get called again. Otherwise, GLUT has no way to know that your scene needs to be redrawn.
  • Although you're performing a transformation in handleKeypress, drawScene clears that out by calling glLoadIdentity() on the modelview matrix. You'll need to add some smarts so that the appropriate gluLookAt call (only one!) happens after glLoadIdentity().
Good luck!