PDA

View Full Version : Viewport distortion- even with proper aspect ratio



keelx
07-28-2011, 06:16 PM
Here is my setup code for the projection, viewports, etc.:


glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 640/480, 0.1, 1000);
glMatrixMode(GL_MODELVIEW);

And here is my drawing code:


glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
glPushMatrix();
glBegin(GL_QUADS);
glVertex3i(-5, -5, -20);
glVertex3i(5, -5, -20);
glVertex3i(5, 5, -20);
glVertex3i(-5, 5, -20);
glEnd();
glPopMatrix();


Because I have set my aspect ratio to 640/480, I'd think the quad would display as a square. But nope, it is displayed as a rectangle with a 4/3 width to height ratio. What am I missing here?

Xmas
07-29-2011, 05:18 AM
640/480 is 1. What you want is 640.0/480.0.

keelx
08-01-2011, 01:27 PM
Thanks! It works as expected now.