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

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();

}

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)

It was integer maths, changing to floats fixed it :smiley: