PDA

View Full Version : glOrtho, how does it work?



Banangroda
08-09-2008, 05:15 PM
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?

dletozeun
08-10-2008, 03:52 AM
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.

Banangroda
08-10-2008, 09:49 AM
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?

dletozeun
08-10-2008, 10:46 AM
(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.

Banangroda
08-10-2008, 11:17 AM
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();?
http://img401.imageshack.us/img401/1033/skrmbild1fj9.th.png (http://img401.imageshack.us/my.php?image=skrmbild1fj9.png)

The bottom clipping "border" seems to just have expanded from the white polygon and produced a white background...

dletozeun
08-10-2008, 12:04 PM
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.

Banangroda
08-10-2008, 03:52 PM
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!

dletozeun
08-11-2008, 12:21 AM
hmm, yes! I have inverted.