Most of my work with OpenGL has been using orthographic projection. Now I need perspective projection, and things rather mysteriously aren’t working, and I’m not sure why.
I have some dummy code set up just to test things out:
glViewport(0,0,500,500);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1,0,10);
//glOrtho(-1,1,-1,1,0,2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(1,0,1,
0,0,0,
0,0,1);
glClearColor(1,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glPointSize(5);
glColor3d(0,1,0);
glBegin(GL_POINTS);
glVertex3d(0,0,0);
glVertex3d(.1,0,0);
glVertex3d(0,.1,0);
glEnd();
When I use the glOrtho line, it works fine, and I get three green dots on a red background. But when I switch to the gluPerspective instead, the dots don’t show up?
Curiously, one of the three dots (the one in the center) does show up if I comment the gluLookAt(). I think this is because (0,0,0) is right at the root of the frustum and this is also the untransformed camera location.
Any suggestions?