Jump to content
  • Advertisement
Sign in to follow this  
Luca Galbusera

OpenGL Using glOrtho

This topic is 2543 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!
I'm reading OpenGL SuperBible third edition and at page 56 it uses the function glOrtho as

glOrtho(-100, 100, -yrange, yrange, 1, -1);

I don't understand why z near is set to 1 and z far is set to -1, shouldn't be z near = -1 and z far=1?

Share this post


Link to post
Share on other sites
Advertisement
What is should be depends on what you want from it. All it means by having near=1 and far=-1 is that eye-space Z-values at 1 maps to depth buffer value 0 (that's where the near plane ends up), and that eye-space Z-values at -1 maps to depth buffer value 1 (that's where the far plane ends up).

All glOrtho does is setting up a coordinate system, and the parameters describes the visible limits along each axis. Anything else is only an interpretation of what that means.

Share this post


Link to post
Share on other sites
Generally glOrtho is used for rendering 2D GUI overlay stuff (or fullscreen quads resulting from post-processing), and generally it's always rendered in back-to-front order with Z = 0 and depth test/write disabled, so the precise values used for znear and zfar don't really matter too much; so long as they encompass the Z value used for your GUI stuff (like I said, typically 0) then it's OK.

If you're using glOrtho for something else then they might matter (it depends on what that something else is) and you should refer to Brother Bob's answer.

Note that in modern OpenGL there is no glOrtho - you would construct your own matrix and use that (or bypass matrix multiplication and just scale positions appropriately in your vertex shader).

Share this post


Link to post
Share on other sites

What is should be depends on what you want from it. All it means by having near=1 and far=-1 is that eye-space Z-values at 1 maps to depth buffer value 0 (that's where the near plane ends up), and that eye-space Z-values at -1 maps to depth buffer value 1 (that's where the far plane ends up).

All glOrtho does is setting up a coordinate system, and the parameters describes the visible limits along each axis. Anything else is only an interpretation of what that means.


So, if I use this convention then the positive z-axis points towards the screen, while the negative z-axis is coming out from the screen? I.e. the larger the z value, the deeper in the screen the object is?


Share this post


Link to post
Share on other sites

So, if I use this convention then the positive z-axis points towards the screen, while the negative z-axis is coming out from the screen? I.e. the larger the z value, the deeper in the screen the object is?

No. In OpenGL view direction is towards negative Z in view coordinate system. Thus the smaller is Z, the closer object is and the larger is Z the further object is.
Near view plane has maximum and far view plane minimum Z value (in view coordinate system) - hence the values 1 and -1.

Share this post


Link to post
Share on other sites

[quote name='Luca Galbusera' timestamp='1317820955' post='4869393']
So, if I use this convention then the positive z-axis points towards the screen, while the negative z-axis is coming out from the screen? I.e. the larger the z value, the deeper in the screen the object is?

No. In OpenGL view direction is towards negative Z in view coordinate system. Thus the smaller is Z, the closer object is and the larger is Z the further object is.
Near view plane has maximum and far view plane minimum Z value (in view coordinate system) - hence the values 1 and -1.
[/quote]

Uhm.. i think I understood (I guess!). But in this case to show the objects correctly I need to use glDepthFunc(GL_GEQUAL), is it right? Because the further the object, the smaller Z is?


Share this post


Link to post
Share on other sites
No, the depth test comparison operates on depth buffer values. An object at the far plane will always have a greater depth buffer value than an object at the near plane, no matter how you configure your near and far clip planes. That is what I said in my first post; the near plane maps to a depth buffer value of 0, and the far plane maps to a depth buffer value of 1.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!