gluOrtho2D

I’m working on examples from the Red Book. I’m trying to get a triangle to appear using gluOrtho2D but nothing appears. Here’s my code. Strangely enough when I uncomment the gluPerspective line and comment out gluOrtho2D the triangle appears:

#include “…/include/GL/glut.h”

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}

void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex2f(-1.0, 0.0);
glVertex2f(1.0, 1.0);
glVertex2f(1.0, -1.0);
glEnd();
glFlush();
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(-10.0,10.0,-10.0,10.0);
//gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

gluLookAt is meant to be used alongside either gluPerspective or glFrustum. That is, it creates a matrix to transform from “world” space to the camera space defined by these two functions. It doesn’t work with an orthographic projection, as orthographic space is ultimately just a scale/translation of normalized device coordinate space.

so how do I get the triangle to show up using gluOrtho2D?

delete gluLookAt.

Thanx a lot!