openGL rendering glulookat

Tag: opengl Author: gracewang1986 Date: 2013-06-09

I rendered a triangle in the scene but now that I'm adding mouse navigation nothing seems to work anymore. So I deleted all the navigation stuff again to see what was wrong with my use of gluLookAt(). But even in a very simple case I dont see anything:

void GLScene::paintGL() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();


    //m_navigation.UpdateCamera();

    gluLookAt(0 ,0 ,20,
        0,0,-1,
        0, -1, 0 );

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1,0,0);
    glBegin(GL_POLYGON);
    glVertex3f(0,0,0);
    glVertex3f(0,100,0);
    glVertex3f(100,0,0);
    glEnd();


}

Other Answer1

you messed up your object transformation matrices

correct code (untested)

void GLScene::paintGL() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   gluLookAt(0 ,0 ,20,
    0,0,-1,
    0, -1, 0 );

   glClear(GL_COLOR_BUFFER_BIT);
   glColor3f(1,0,0);
   glBegin(GL_POLYGON);
   glVertex3f(0,0,0);
   glVertex3f(0,100,0);
   glVertex3f(100,0,0);
   glEnd();
}