glOrtho, how does it work?

Hi. Could someone please explain this? I’m trying to figure out what glOrtho(0.0, 1.0, 0.1, 1.0, -1.0, 1.0); does exactly, on a not so technical level. I’m testing the http://www.opengl.org/resources/code/samples/redbook/hello.c code. It just doesn’t do what I expected it to do when I changed the left/right/bottom/top parameters. Why do the clipping planes seem to expand from the square, and why is that extra space white?

glOrtho sets an orthographic projection. In your case polygons outside the [0 1]x[0 1]x[-1 1] volume are discarded because they are not visible.

see http://www.opengl.org/sdk/docs/man for more information.

Why do the clipping planes seem to expand from the square, and why is that extra space white?

I am not sure to understand what you mean here.

Change those values to glOrtho(0.1, 1.0, 0.1, 1.0, -1.0, 1.0); for instance and run it. Why has the white area expanded?

(left, bottom, -near) is the coordinates of the screen lower left corner and (right, top, -near) the upper right one. Or just read the glOrtho spec.

Yeah. So why does glOrtho(0.0, 1.0, 0.2, 1.0, -1.0, 1.0); result in the following when the polygon I draw is glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
glVertex3f(0.25, 0.75, 0.0);
glEnd();?

The bottom clipping “border” seems to just have expanded from the white polygon and produced a white background…

I don’t think you understand the spec or what I have said. There is no “white background”.
Putting 0.2 for bottom value just move the bottom clip space 0.2 units upper.
With glOrtho, horizontal coordinates goes from left to right and vertical ones from bottom to up.

In your example 0.2 is the bottom of the window and you draw a quadat 0.25, then window left border is at 0.0 and the closest quad border is at 0.25 too. So as expected, quad left border is closer to the window left border that quad bottom border to the window bottom border.

And your quad is deformed because your window is a square but your coordinates space not.

Ahh! So nothing outside the clipping space is shown inside the window? That explains why the quad appears to be deformed.

In your example 0.2 is the bottom of the window and you draw a quadat 0.25, then window left border is at 0.0 and the closest quad border is at 0.25 too. So as expected, quad left border is closer to the window left border that quad bottom border to the window bottom border.

Hm. Isn’t the 0.2 bottom border closer to the 0.25 bottom of the quad than the 0.0 left border and the 0.25 left quad border… ?

By the way, thanks for helping me out!

hmm, yes! I have inverted.