View Full Version : Window Size and gluOrtho2D

02-25-2003, 07:07 PM

This is what I did?

1. glutInitWindowSize(400, 400);

2. gluOrtho2D(100, 300, 100, 300);

Why does the window that shows up only show the gluOrtho2D coordinates?

Isn't gluOrtho2D just the clipping region as in the area outside of the clipping region but in the window size will be a border? Or am I incorrect in assuming that?

If only the clipping region will be viewable, then what is the point of the Window Size? Why not just specify the size using gluOrtho2D?


02-25-2003, 07:27 PM
glutInitWindowSize sets the size of the window.

gluOrtho2D specifies the coordinates to be used with the viewport which defaults to the window size.

Use glViewport to specify the window region in window coordinates to be drawn to.

So, if you want create a 400 x 400 window and only want to draw to the rectangle(50, 50, 350, 350) within the window, then use glViewport(50, 50, 300, 300). You would then use gluOrtho2D to set your GL coordinates wthin the viewport. So, if you used gluOrtho2D(-1.0, 1.0, 0.0, 1.0) then visible GL coordinates would range from -1.0 to 1.0 in the x direction, from 0.0 to 1.0 in the y direction. And, if you used the gluOrtho2D as you showed in your post, then visible coordinates would range from 100 to 300 in the x direction and from 100 to 300 in the y direction.

At the same time if you were to draw a square with coordinates {(-0.25,0.25),(0.25,0.25),(0.25,0.75),(-0.25,0.75)} it would appear on the screen as a rectangle with height twice the width because the aspect ratio of the gluOrtho2D command is 2 to 1 with respect to x and y. Typically, aspect ratios are maintained for both so that images do not appear distorted.

[This message has been edited by shinpaughp (edited 02-25-2003).]

[This message has been edited by shinpaughp (edited 02-25-2003).]