macoscocoaopenglglslnsopenglview

OpenGL: Can see through one wall but not the other


I do not know whether this is a depth buffer issue or another. I can see through one wall but not another:

Wall viewable

Now when I rotate so the second wall becomes more prominent:

enter image description here

enter image description here

I have the depth buffer enabled in Interface Builder. My OGL enables look like this:

// enables
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_SMOOTH);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_CULL_FACE);
//glCullFace(GL_BACK);
glFrontFace(GL_CCW);
//glDepthMask(GL_TRUE);
//glDepthFunc(GL_LESS);

Any suggestions. I commented out the other enables as they did not seem to help.

As request, here is the projection and modelview setup:

// initialize all rotation matrices, translation matrix, and model view matrix to identity
rotateX = GLKMatrix4Identity;
rotateY = GLKMatrix4Identity;
rotateZ = GLKMatrix4Identity;
modelMat = GLKMatrix4Identity;

zNear = 0.1;

zFar = 1000.0;

frustumScale = 1.0;

//GLint maxbuffers;
//glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxbuffers);
//NSLog(@"Max. number of buffers: %d", maxbuffers);

// called?
NSLog(@"awakeFromNib called...");

// set the aspect ratio here
NSSize dim = [self frame].size;
aspectRatio = dim.width/dim.height;

// compute the projection matrix
projMat = GLKMatrix4MakePerspective(frustumScale, aspectRatio, zNear, zFar);

...

// compute the model matrix
GLKMatrix4 tempLeft = GLKMatrix4Multiply(rotateX, rotateY);
GLKMatrix4 tempRight = GLKMatrix4Multiply(rotateZ, translation);
modelMat = GLKMatrix4Multiply(tempLeft, tempRight);

Solution

  • Solved it!!!!

    Setting up the depth buffer via Interface Builder seems to not be working. I had to programmatically set it up, and the problem was solved.

    NSOpenGLPixelFormatAttribute attribute[] = {NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24, 0};