PDA

View Full Version : Any clues on why depth buffering isn't working for me?



shillis
05-17-2000, 04:57 AM
Hello all,

I am using OpenGL 1.2 with an STB nVidia TNT card. I setup a double buffered GLUT window with a depth buffer by calling:
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );

I then enable Depth testing by calling:
glEnable( GL_DEPTH_TEST );

And the first thing I do for each display callback is clear the depth buffer:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

But all I get is a blank screen. If I disable depth testing, then my polygons are displayed by the reverse order in which they were drawn. It doesn't even seem to work properly on a machine with a Creative Labs TNT2 Ultra. Is this possibly a card/driver problem?

AndersO
05-17-2000, 05:36 AM
Have you set up the frustum?.. Specified near and far z plane?.

shillis
05-17-2000, 05:56 AM
Yes. I'm using gluPerspective and have specified the near and far planes with that. I can verify that that part works correctly if I disable DEPTH_TEST and then move around.

Humus
05-17-2000, 11:51 AM
Have you set up any depthtest function with glDepthFunc()?

shillis
05-17-2000, 12:29 PM
If one is not specified, it defaults to using GL_LESS. But I have tried calling glDepthFunc with all 8 variants - GL_LESS, GL_GREATER, etc. GL_NEVER appropriately gives a blank screen and GL_ALWAYS is the same as having no depth test.

Using GL_GREATER actually seems to work appropriately. It gives a blank screen if I set glClearDepth( 1.0 ) and does proper drawing if I set glClearDepth( 0.0 ). But GL_LESS just gives a blank screen with either glClearDepth setting or if I don't specify one - which I believe defaults to 1.0. And, of course, GL_LESS is the one that I need to have working.

shillis
05-18-2000, 08:28 AM
First off, let me thank AndersO and Humus for trying to help and all those that read this thread with the intent of helping.

Second, I found my problem. A lesson learned the hard way for me is to not set your near clipping plane to 0. Bad and unexpected things can happen. So I set it to .1 and things work as they should.

Kaeto
05-19-2000, 05:41 PM
Yeah, ANY number that quantitizes to > 0 (i.e. you FPU doesn't round it to zero) is fine http://www.opengl.org/discussion_boards/ubb/smile.gif

bugatti
05-21-2000, 08:22 PM
Originally posted by shillis:
Hello all,

I am using OpenGL 1.2 with an STB nVidia TNT card. I setup a double buffered GLUT window with a depth buffer by calling:
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );

I then enable Depth testing by calling:
glEnable( GL_DEPTH_TEST );

And the first thing I do for each display callback is clear the depth buffer:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

But all I get is a blank screen. If I disable depth testing, then my polygons are displayed by the reverse order in which they were drawn. It doesn't even seem to work properly on a machine with a Creative Labs TNT2 Ultra. Is this possibly a card/driver problem?



You say you are using opengl 1.2.

Where did you get the implementation?

Kaeto
05-22-2000, 05:14 AM
I think he's just saying he's writing 1.2 code http://www.opengl.org/discussion_boards/ubb/smile.gif