Jump to content
  • Advertisement
Sign in to follow this  
movesax

OpenGL glOrtho z-clipping planes

This topic is 3494 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

First time post here and I'm a beginner with OpenGL. I've also searched around quite a bit to try to find some help. I set: glOrtho(-1.0,1.0, -1.0, 1.0, -100.0, 100.0); So, I glLoadIdentity then draw a Wireframe model. then I glTranslate to (0,0,1) and draw a coordinate system. then I glTranslate to (0,0,4) to look at everything. Everything looks and behaves just fine. I then decide I want to clip the far half of my wireframe model... because it's kinda confusing having it there. I have the bright idea of moving the back half of my clipping plane forward to just clip that out. Well, I tried what I thought would work with glOrtho... it didn't. Then I tried all sorts of stuff... and nothing is behaving like I expected. Sometimes my z-coordinate even flips backwards (+z changes from out of the screen to into). Two Questions: 1) How can I complete my goal of clipping the back half of my wireframe model, while keeping my drawn coordinate axis in front? 2) What's going on here? How does glortho work?! Is it relative to the final 'camera position.' Is it relative to the origin as defined by glLoadIdentity. Does every glBegin()/glEnd() segment have it's own clipping box? thanks for your time :)

Share this post


Link to post
Share on other sites
Advertisement
It's been a while since i played around with OpenGL but sounds like you want backface culling.
Did you enable backface culling and set it to CCW(counterclock-wise)or CW?

Share this post


Link to post
Share on other sites
glOrtho sets up an orthogonal projection matrix, which would make the view frustum be relative to the final camera position.

Basically, if if your camera is located at (0, 0, -5) at the end (translating the scene by positive z is the same as translating the camera by negative z), your clipping planes would now be at near.z = -105 and far.z = 95.

Clipping your wireframe model would require to set the clipping planes accordingly, depending on the size/position of the model.

The better way, however, would be to use user defined clipping planes: have a look at glClipPlane(...).

You can enable your clip plane before drawing the wireframe model and disable it afterwards.

Hope that helps.

Thomas

Share this post


Link to post
Share on other sites
awesome!! you pointed me in the right direction to better understand what was going on and a better way of doing this.

There's 1 small odd thing.

If I place a ball @ (0,0,-1.0)
then, I set glOrtho(-1.0,1.0, -1.0, 1.0, -5, 1);

I get my ball clipped in half... which would imply to me that glortho considers
+Z into the scene. While the rest of OpenGL has -Z into the scene. Is that correct?

I did end up using glClipPlane().

:D

Share this post


Link to post
Share on other sites
(+z changes from out of the screen to into).

You realize that near and far plane should both be positive right? Basically if you think of you head as the GL camera. Your saying that anything 100 units behind you and 100 units in front of you , you can see. Those should both be positive.

Share this post


Link to post
Share on other sites
Again, you have a camera film at 0. The stuff in front of you looks fine, but the stuff behind you gets drawn over the stuff in fron of you. And its probably flipped.

make it glOrtho(..,...,....,..,..., 0, 100).

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!