Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: glOrtho, how does it work?

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    8

    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...edbook/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?

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: glOrtho, how does it work?

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    8

    Re: glOrtho, how does it work?

    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?

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: glOrtho, how does it work?

    (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.

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    8

    Re: glOrtho, how does it work?

    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...

  6. #6
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: glOrtho, how does it work?

    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.

  7. #7
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    8

    Re: glOrtho, how does it work?

    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!

  8. #8
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: glOrtho, how does it work?

    hmm, yes! I have inverted.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •