PDA

View Full Version : My 3D graphics strech if my aspect ratio isn't 1:1



Bluebomber357
10-23-2009, 04:25 PM
Sorry if this topic has been answered before on these forums. I searched google, my superbible book, and these forums, but I must not know the right keywords to find my answer.

Basically, my 3D graphics look stretched if my aspect ratio is not a perfect 1:1, how do I fix this?

Here is what I am currently using:

void changeSize(int w, int h) //called when the application window is resized
{
ratio = 1.0f * w / h;

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Set the clipping volume
gluPerspective(45,ratio,1,1000);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glutPostRedisplay();
}

Ilian Dinev
10-23-2009, 06:58 PM
Are you sure changeSize() is being called? Or that the gl_projection matrix is not modified elsewhere too.

Or that your compiler correctly calculated "ratio". (could be doing integer maths)

Bluebomber357
10-23-2009, 07:21 PM
It was integer maths, changing to floats fixed it :D