Advertisement

Depth buffer not working

Started by September 22, 2001 07:05 PM
5 comments, last by feagle814 23 years, 5 months ago
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
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().
Advertisement
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?
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.  
how about

glCullFace(FRONT_AND_BACK);

does it work ?

glHorizon_Project



www.web-discovery.net


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
Advertisement
Thanks! The perspective thing was the problem!

This topic is closed to new replies.

Advertisement