0

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);
xBACP
  • 531
  • 1
  • 3
  • 17
  • Are you sure you actually _have_ a depth buffer? – derhass Oct 02 '13 at 23:57
  • A missing depth buffer would be the default guess — assuming the face with no green on it is drawn second? It's hard to figure out what's going on given that you've got one explicitly ticked in IB and you've enabled though. What do you get if you log out a `CGLDescribePixelFormat` call to `openglView.pixelFormat.CGLPixelFormatObj` with `kCGLPFADepthSize`? – Tommy Oct 02 '13 at 23:59
  • Also: enabling glCullFace should have hidden the problem (without resolving it) given that your geometry is convex. Are you sure the enables are performed at all? – Tommy Oct 03 '13 at 00:00
  • @derhass, when I make a call to glGetIntegerv(GL_DEPTH_BITS, &depth) is get 16 bits. – xBACP Oct 03 '13 at 00:05
  • @Tommy, for your comment on glCullFace: If enable it does solve the issue somewhat, but when I rotate the object I cannot see the back... – xBACP Oct 03 '13 at 00:07
  • Also, how come I cannot see the first wall through the second wall in picture 3? – xBACP Oct 03 '13 at 00:10
  • @OneDaySoon my suspicion, and derhass', is that depth buffering isn't working for whatever reason. So the polygons are added to the display in the order you specify them. Since you specify the wall-without-green second, it'll always be on top. If you could see the other wall in picture 3 then the guess would be that you had the depth test running backwards. EDIT: is it also safe to assume you're not calling `glDepthMask` or anything like that? – Tommy Oct 03 '13 at 00:21
  • @Tommy, no calls to glDepthMask()... – xBACP Oct 03 '13 at 00:31
  • Can you show how you setup your modelview and projection matrices? The depth buffer can be effectively made useless if you setup your projection incorrectly. – Andon M. Coleman Oct 03 '13 at 00:42

1 Answers1

0

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};
xBACP
  • 531
  • 1
  • 3
  • 17