2013-10-02 16 views
0

我不知道这是深度缓冲区问题还是其他问题。我可以通过一个看到墙上而不是另一个:OpenGL:可以透过一面墙而不看到另一面

Wall viewable

现在,当我旋转,使第二壁变得更加突出:

enter image description here

enter image description here

我有深度缓冲在Interface Builder中启用。我的OGL使得看起来像这样:

// 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); 

任何建议。我注意到其他使能,因为他们似乎没有帮助。

作为请求,这里是突起和模型视图设置:

// 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); 
+0

你确定你实际上拥有一个深度缓冲区吗? – derhass

+0

缺少深度缓冲区将是默认猜测 - 假定其上没有绿色的面被绘制第二个?鉴于您已经在IB中明确勾选并且您已启用,因此很难弄清楚发生了什么事情。如果使用'kCGLPFADepthSize'注销'CGGLescribePixelFormat'对'openglView.pixelFormat.CGLPixelFormatObj'的调用,你会得到什么? – Tommy

+0

另外:考虑到你的几何体是凸的,启用glCullFace应该隐藏了问题(不解决它)。你确定启用是否被执行? – Tommy

回答

0

解决它!!!!

通过Interface Builder设置深度缓冲区似乎不工作。我不得不以编程方式设置它,并且问题解决了。

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