🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

OpenGL Depth buffer

Started by
5 comments, last by Jonathan 24 years, 5 months ago
Or at least I think that's where the problem is. I'm playing around with OpenGL, so far just drawing a single triangle on the screen and manipulating it. The odd thing is, if I move it from z=0.0, it disappears. I've set the clear depth to 1.0, and GL_LESS for the depth function, and a far clipping plane of 1000.0, but it's still not working. Anyone have any idea why? Jonathan Correction: The object being draw only appears if it's z-coordinate is between 0.0 and 1.0. And I still have no clue why it's doing it Edited by - Jonathan on 1/10/00 2:36:15 PM
Advertisement
Did you set your viewport to something bigger than the default -1, 1?

Also, remember positive Z numbers are toward the screen. A far clipping plane of 1000 is equal to Z at -1000
-the logistical one-http://members.bellatlantic.net/~olsongt
What exactly is it you mean by viewport? The one set in glViewport(), or another?

Jonathan
Ok, after a good two days worth of trying to figure out what the hell is going on, I have to admit I'm stumped. I have made a few discoveries that may help me out though.

First, the problem. Any point with a z-coordinate outside of the range -1.5 to 1.5 disappears. Almost as if that's where the near and far clipping planes are set. I have set the near and far planes to 0.1 and 1000 respectively. I've tried setting the near plane to 0.00000000001 and the far plane to 100000000000.0, but it hasn't made any difference.

I thought for a while that it might be a problem with the depth buffer, but turning off depth buffering doesn't fix it.

I added in some code to let me move the object I'm drawing around, it'll translate along the x and y axes just fine, but along the z-axis it doesn't appear to move. What it looks like is that I'm moving the clipping planes about. The program can be seen here. The mouse will rotate the diamond, while the arrow keys translate it along the x and z axes. Escape or Alt-F4 to quit.

If anyone might have an idea as to where the hell I screwed up, please tell me I'm lost

Jonathan

Correction: It would appear that the range of z-coordinates that are getting drawn depends on the implementation. 3dfx's gives the -1.5 to 1.5, while Microsoft's gives -2 to 2. Not that I see any way that could help, but oh well

Edited by - Jonathan on 1/12/00 12:19:07 AM
Have you already tried glDepthRange()?

quoting from the OpenGl blue book :
quote:
NAME

glDepthRange - specify the mapping of z values from normalized device coordinates to window coordinates

C SPECIFICATION

void glDepthRange( GLclampd near, GLclampd far )

PARAMETERS

near
Specifies the mapping of the near clipping plane to window coordinates. The default value is 0.

far
Specifies the mapping of the far clipping plane to window coordinates. The default value is 1.

DESCRIPTION

After clipping and division by w, z coordinates range from -1.0 to 1.0, corresponding to the near and far clipping planes. glDepthRange specifies a linear mapping of the normalized z coordinates in this range to window z coordinates. Regardless of the actual depth buffer implementation, window coordinate depth values are treated as though they range from 0.0 through 1.0 (like color components). Thus, the values accepted by glDepthRange are both clamped to this range before they are accepted.
The default mapping of 0,1 maps the near plane to 0 and the far plane to 1. With this mapping, the depth buffer range is fully utilized.


Edited by - Chappa on 1/12/00 6:50:51 AM
::sigh:: Yes, I tried that, to no avail.

Jonathan
Alright, I fixed it. It turned out to be my stupid ass setting certain things before I set up the projection matrix. ::sigh:: Here''s the working result, if anyone''s interested.

Jonathan

This topic is closed to new replies.

Advertisement