tags:

views:

33

answers:

2

I am drawing several shapes (such as circles) that are keyed off of the window height & width. Since the window always starts at a given size, they are drawn correctly, but when the window is resized, it messes the aspect ratio up.

How can I draw the shapes properly, regardless of window size?

+1  A: 

If you're using something like gluPerspective() just use the window width/height ratio:

gluPerspective(60, (double)width/(double)height, 1, 256);
genpfault
+1  A: 

You definitely don't want to make the size of your objects explicitly dependent on the window size.

As already suggested by genpfault, adjust your projection matrix whenever the window size changes.

Things to do on window resize:

  1. Adjust viewport:

    glViewPort(0,0, width, height)

  2. Adjust projection matrix:

    glFrustum(left * ratio, right * ratio, bottom, top, nearClip,farClip)

    or

    glOrtho(left * ratio, right * ratio, bottom, top, nearClip,farClip)

    or

    gluOrtho2D(left * ratio, right * ratio, bottom, top)

    (assuming that left, right, bottom and top are all equal and ratio=width/height)

Greg S