aspect ratio

Hi,
I’m looking for a help on understanding aspect ratio. I understand how after specifying a clipping volume the final image may be stretched or squashed when the window size is changed. However, I don’t understand why passing an aspect ratio(width over a height) can avoid this effect. Can anyone explain it to me???
Thanks,
renderZ

The clipping volume has nothing to do with images being squashed or stretched. The clipping volume defines a clipping region for vertices. Any vertices within the clipping volume are kept, those outside the volume are clipped and a new polygon is formed using the clipping plane responsible for clipping a vertex.

The aspect ratio is passed to the gluPerspective function because it is used for perspective transformations. The aspect ratio is used to define the viewers ‘field of view’.
If you resize the scene you’ll notice that the objects still undergo some distortion but the perspective transforms are still intact.

In OpenGL i think the viewport has to have an aspect ratio of 2:1 for there to be no distortion…

In OpenGL i think the viewport has to have an aspect ratio of 2:1 for there to be no distortion…
Sorry, but it is completely wrong.

Frankly what Aeluned said is utter nonsense.

The aspect ratio is calculated like this:

aspect ratio = width/height.

So if your window is 800/600 its 4:3,
if its 1024/768 its still 4:3.

In general the aspect ratio defines how many pixels are required (in x and y) to cover a region that “appears” as a square on the screen.

In other words if you have a aspect ratio of 4:3 and you want to draw a square with a height of 30 pixels, you need to draw a 40x30 pixel rectangle, only this will “look” like a square on the screen.

In other words if you have a aspect ratio of 4:3 and you want to draw a square with a height of 30 pixels, you need to draw a 40x30 pixel rectangle, only this will “look” like a square on the screen.
No, no, no. You just messed “screen aspect ratio” and “pixel aspect ratio”.

  1. Screen aspect ratio : as you mentionned it, it is commonly 4/3 (for 800/600 and 1024/768 when the pixels are square).

  2. pixel aspect ratio : if you have a 16/9 display used to display 800/600 pixels, the pixels will end up rectangular.

Most of the time, you can assume that screen pixels are square. So to display a square, display something 30x30.

Back to openGL, to have a correct aspect ratio of the projected scene, you have to get the width and height of your GL window.
Then, tell it to opengl, ie :

glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, float(Width)/float(Height), 0.1, 100.0);

You should know that gluPerpective “fills” the glViewport with the GL rendering. So if you have a screen resolution of 800 by 600 pixels displayed on a 16/9 lcd display (so you have rectangular pixels), here is how to end up with correct visual aspect :

glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 16.0/9.0*float(Width)/float(Height), 0.1, 100.0);