OpenGL gluLookAt() not doing anything?

Post: #1
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
Quote this message in a reply
Posts: 1,563
Joined: 2003.10
Post: #2
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!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  gluLookAt problem vobla 0 3,559 Sep 1, 2007 12:44 PM
Last Post: vobla
  gluLookAt vs. glRotatef/glTranslatef...etc hangt5 9 12,260 Mar 15, 2005 12:54 PM
Last Post: OneSadCookie
  Problems with gluLookAt(); ghettotek 6 7,679 Feb 9, 2003 04:35 AM
Last Post: ghettotek