Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

feagle814

Depth buffer not working

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

For some reason, my attempt to create a depth buffer in my program is just not working. The program is a simple test program that pretty much shows a rotating dog statue. It uses SDL. For some reason the polygons behind the dog are showing up: Here's all my code concerning the depth buffer, in the order they're called:
    
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
glClearDepth(1);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
    
Thanks for your help. Edited by - feagle814 on September 22, 2001 8:07:08 PM

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Your SGL_GL_SetAttribute() call needs to be made before your call to SDL_SetVideoMode(). You also need to make all OpenGL related calls after a successful call to SDL_SetVideoMode().

Share this post


Link to post
Share on other sites
Are you sure glDepthFunc(GL_LEQUAL) is right? Try glDepthFunc(GL_LESS), which is the default.
Can you tell us why you''re using LEQUAL?

Share this post


Link to post
Share on other sites
My SDL_GL_SetAttribute is before my SDL_SetVideoMode call; I omitted that call because I thought it was not relevant.

I was using LEQUAL because the tutorials on NeHe''s site recommend it; when I use GL_LESS, the dog does not show up.

If any of this has relevance:
On startup:
  glViewport(0, 0, Video->w, Video->h); 
glShadeModel(GL_SMOOTH);
glClearColor(0, 0, 0, 0.5);
glClearDepth(1);
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_FRONT, GL_FILL);
glFrontFace(GL_CCW);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

On redraw:
  
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, 1.3, 0, 1024);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -2);
ang = (ang + 2) % 360;
glRotatef(ang, 0,1,0);
glColor3f(1, 1, 1);
Dog->draw(); //The dog is drawn by my Object3d object, simply a set of vertices.

Share this post


Link to post
Share on other sites
Hmmm.... Change znear cliping plane from 0 to (for ex.) 0.5f. It should give you a better buffer accuracy. You've also set zfar clip plane at 1024 and it's realy to far for your scene.

Change:
gluPerspective(45, 1.3, 0, 1024);
to:
gluPerspective(45, 1.3, 0.5f,256);

You can anyway change those values, but try to keep znear as close to the model as possible. And never set znear to 0 !!!

Edited by - Dexio on September 24, 2001 1:38:20 PM

Share this post


Link to post
Share on other sites

  • 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!