For some reason z-buffering/depth testing isn’t working in my current project. Polygons display properly except ones in the back can cover up ones in the front. I have had this work in other projects by just putting:
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
in the setup. However, projects I was using before used GLUT and this one does not. Is there something I’m missing? I don’t want to use GLUT.
Thanks,
Keenan Crane
Just to be sure…
Are you sure the pixelformat you’re using has a depth buffer?
You mentioned you were using glut before and now you aren’t, which is the only reason I’m asking…
No, I’m not sure the pixelformat has a depth buffer and I’m also not sure how to check whether it does and how to set it so it does! I’m using a skeleton project so I’m not completely sure how it’s set up. What specifically should I look for?
Thanks,
Keenan Crane
Well here’s what I found, so it looks like I should have a depth buffer:
class GLContext
{
const CGLPixelFormatAttribute* GetPixelFormat(u_int32_t display_id = 0x01, int color = settings.depth, int depth = 0, int stencil = 0)
{
static CGLPixelFormatAttribute attribs[32];
CGLPixelFormatAttribute* attrib = attribs;
*attrib++ = kCGLPFANoRecovery;
*attrib++ = kCGLPFADoubleBuffer;
*attrib++ = kCGLPFAAccelerated;
*attrib++ = kCGLPFAFullScreen;
*attrib++ = kCGLPFADisplayMask; *attrib++ = (CGLPixelFormatAttribute) display_id;
*attrib++ = kCGLPFAColorSize; *attrib++ = (CGLPixelFormatAttribute) color;
*attrib++ = kCGLPFADepthSize; *attrib++ = (CGLPixelFormatAttribute) depth;
*attrib++ = kCGLPFAStencilSize; *attrib++ = (CGLPixelFormatAttribute) stencil;
*attrib++ = (CGLPixelFormatAttribute) 0;
return attribs;
}
…
}
which is later called by:
CGLError err = CGLChoosePixelFormat(GetPixelFormat(display_id, 32), &pixel_format, &num_pixel_formats);
Thanks!
Ok, sorry once again - I set depth = 16 and it works.