简体   繁体   English

在iOS 5上使用MonoTouch无法使用OpenGL ES 1.1深度缓冲区

[英]OpenGL ES 1.1 depth buffer not working using MonoTouch on iOS 5

I can't get the depth buffer to work using MonoTouch on iOS 5. I'm using the standard MonoTouch "OpenGL Application" template and added this code to test the depth buffer (OpenGL ES 1.1): 我无法在iOS 5上使用MonoTouch来使深度缓冲区工作。我使用标准的MonoTouch“OpenGL应用程序”模板并添加此代码来测试深度缓冲区(OpenGL ES 1.1):

GL.Enable(All.DepthTest);
GL.DepthFunc(All.Greater);
GL.DepthMask(true);

// Shape A
GL.DrawArrays (All.TriangleStrip, 0, 4); 

// Shape B (should be behind Shape A)
GL.Translate (.5f,.5f,.5f);
GL.DrawArrays (All.TriangleStrip, 0, 4); 

// Shape C (should be in front of Shape A)
GL.Translate (-1f,-1f,-1f);
GL.DrawArrays (All.TriangleStrip, 0, 4);

Both shape B and C are drawn in front of shape A. The same thing happens even with "GL.DepthFunc(All.Never)". 形状B和C都绘制在形状A的前面。即使使用“GL.DepthFunc(All.Never)”也会发生同样的事情。 The depth buffer is completely ignored. 深度缓冲区完全被忽略。 I also tried manually creating a depth buffer (instead of relying on the MonoTouch/OpenTK "iPhoneOSGameView" to create one for me) using this code: 我还尝试使用以下代码手动创建深度缓冲区(而不是依赖MonoTouch / OpenTK“iPhoneOSGameView”为我创建一个):

protected override void CreateFrameBuffer()
{
    base.CreateFrameBuffer();    
    uint depthbuffer=0;
    GL.Oes.GenRenderbuffers (1, ref depthbuffer);
    GL.Oes.BindFramebuffer (All.RenderbufferOes, depthbuffer);
    GL.Oes.RenderbufferStorage (All.RenderbufferOes, All.DepthComponent16Oes, (int) 768, (int) 1024);
    GL.Oes.FramebufferRenderbuffer (All.FramebufferOes, All.DepthAttachmentOes, All.RenderbufferOes, depthbuffer);
}

It's still not working. 它仍然无法正常工作。 Do you have any idea how I can get the depth buffer to work? 你知道如何让深度缓冲区工作吗? Am I missing something? 我错过了什么吗?

Thanks to the NeHe-Lesson holmes posted, I found a solution: I use the methods in "OpenTK.Graphics.ES20.GL" instead of those in "OpenTK.Graphics.ES11.GL.Oes" to create the depth buffer. 感谢发布的NeHe-Lesson holmes,我找到了一个解决方案:我使用“OpenTK.Graphics.ES20.GL”中的方法而不是“OpenTK.Graphics.ES11.GL.Oes”中的方法来创建深度缓冲区。 After the buffer is created, I can use the standard OpenGL 1.1 methods in "OpenTK.Graphics.ES11" for the rest of my program. 创建缓冲区后,我可以在“OpenTK.Graphics.ES11”中使用标准的OpenGL 1.1方法来完成我的程序。 Here's the code: 这是代码:

OpenTK.Graphics.ES20.GL.GenRenderbuffers (1,ref depthRenderBuffer);
OpenTK.Graphics.ES20.GL.BindRenderbuffer (OpenTK.Graphics.ES20.All.Renderbuffer, depthRenderBuffer);
OpenTK.Graphics.ES20.GL.RenderbufferStorage (OpenTK.Graphics.ES20.All.Renderbuffer, OpenTK.Graphics.ES20.All.DepthComponent16, Size.Width, Size.Height);
OpenTK.Graphics.ES20.GL.FramebufferRenderbuffer (OpenTK.Graphics.ES20.All.Framebuffer, OpenTK.Graphics.ES20.All.DepthAttachment, OpenTK.Graphics.ES20.All.Renderbuffer, depthRenderBuffer);

Try the following. 请尝试以下方法。

GL.ClearDepth(1.0f);    
GL.Enable(All.DepthTest);   
GL.DepthFunc( All.Lequal);  

Also do not forget to clear the depth on each render. 另外不要忘记清除每个渲染的深度。

GL.Clear((int)(All.ColorBufferBit | All.DepthBufferBit));

I posted my code for the NeHe lessons using MonoTouch on Github while I was learning. 在我学习的时候,我在Github上使用MonoTouch发布了我的NeHe课程代码。 This is the first lesson that requires depth testing and my give you some more info. 是需要深度测试的第一课,我会给你更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM