Anonymous
April 22, 2009

Perspective help with OpenGL (mesa)

HI Guys,

I am trying to create a perspective of a twisted square (ie, the squares sides getting smaller the further it is away from the camera).
Unfortunately, the scene ends up looking like an orthographic projection. Can anyone suggest what I am doing wrong?

void init() {
glClearColor(1, 1, 1, 0);

// projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, 60, 0, 1);
gluLookAt (0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
//glOrtho(-1, 1, -1, 1, 1, -1);

// set up model view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void draw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glRotated(45, 0, 1, 0);
glColor3d(0.5, 1, 0.5);
glutSolidCube(1);
glPopMatrix();

glutSwapBuffers();
}

void reshape(int w, int h) {
glViewport(0, 0, w, h);
}

int main (int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
glutCreateWindow("OpenGL Window");
init();
glutDisplayFunc(draw);
glutIdleFunc(idle);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

Many Thanks,
Tom Medhurst