Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Change eye position of gluLookAt() doesn't work

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    5

    Change eye position of gluLookAt() doesn't work

    Hi all,

    I am a beginner of OpenGL, and I am practicing with gluLookAt(). I want to see that when I change the eye position of gluLookAt(), then the 3D figure shown on the screen changed accordingly (smaller or bigger, rotate left/right/up/down). However, it doesn't. No matter what value I set for the eye position, the figure always appears to be the same.

    The following is my code related with gluLookAt():
    Code :
    void
    reshape(int w, int h){
        glViewport( 0, 0, (GLsizei) w, (GLsizei)h );
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluPerspective( 65.0, (GLfloat) w / h, 1.0, 100.0 );
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();
        gluLookAt( 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );
    }
    Code :
    void
    display(void){
        glClear(GL_COLOR_BUFFER_BIT);
        glClearColor(1.0f, 0.65f, 0.0f, 0.5f);
     
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
        gluLookAt( 100, 0, 0, 0, -0.456398, 1 , 0, 1,  0 );
        glLoadIdentity();
     
        glPushMatrix();
        glBegin(GL_TRIANGLES);
            //a set of vertex for the triangles
        glEnd();
     
        glPopMatrix();
        glutSwapBuffers();
        glReadBuffer( GL_FRONT );
    }
    May I ask what did I do wrong?

    Thank you very much.


  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Change eye position of gluLookAt() doesn't work

    display(void){
    glClear(GL_COLOR_BUFFER_BIT);
    glClearColor(1.0f, 0.65f, 0.0f, 0.5f);

    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    gluLookAt( 100, 0, 0, 0, -0.456398, 1 , 0, 1, 0 );
    glLoadIdentity();
    ..because you have issued glulookat in the display function which then overrides the value set in the reshape() function.
    Additionally, you then reset the camera back to identity!

    Swap these two round:
    gluLookAt( 100, 0, 0, 0, -0.456398, 1 , 0, 1, 0 );
    glLoadIdentity();

    so it becomes

    glLoadIdentity();
    gluLookAt( 100, 0, 0, 0, -0.456398, 1 , 0, 1, 0 );

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •