Search code examples
c++openglglutfreeglut

explanation of glFrustum() compared to gluLookAt()


I'm debugging a code where i want to look at a scan of a depth image, but my camera setup doesn't let me see the scan. Thus, i'm playing around with camera setups. I create a huge point at (30,120,800) and i can see it using gluLookAt. What is the according setup for glFrustum(left, right, bottom, top, near, far)? Using my setup, the point should lay exactly in the center, but i cannot see it.

void onDisplay()
{
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glDisable(GL_CULL_FACE);
glPushMatrix();
glPointSize( 1111111116.0 );
glColor3f( 0.25f, 0.907, 0.731f );
glLoadIdentity();
// Set the camera
//gluLookAt(    30.f, 120.0f, 800.f, 30.f, 120.0f, 800.f, 0.0f, 1.f,  0.0f); //works
glFrustum( 28, 32,     118,     122,   798,     802);
glBegin( GL_POINTS );


glVertex3f( 30, 120, 800 );    //30,120,800

glEnd();

glPopMatrix();
//glFinish();
//glutSwapBuffers();
glutSwapBuffers();
glutPostRedisplay();
}

int main(int argc, char **argv)
{
// initialize GLUT
glutInitWindowSize(800, 800);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

glutInit(&argc, argv);

glutCreateWindow("HeadPoseDemo");


glutKeyboardFunc (processSpecialKeys);

glutDisplayFunc(onDisplay);
glutMainLoop();
return 0;
}

Solution

  • The devil's in the details: Note how in the documentation they say

    nearVal, farVal

    Specify the distances to the near and far depth clipping planes. Both distances must be positive.

    That's different from the wording they use for the other parameters:

    left, right

    Specify the coordinates for the left and right vertical clipping planes.

    What you're expected to know is that you're looking along the negative z-axis. So my guess is that you're going to see your point when you change it to glVertex3f(30.f, 120.f, -800.f);.