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():


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 );
}


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.

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 );