简体   繁体   English

使用GLKit在OpenGL ES 2.0中产生奇怪的混合效果

[英]Strange blending effect in OpenGL ES 2.0 using GLKit

This happens on GLKit with MonoTouch 5.3, but I think the problem may be of general OpenGL ES 2.0 nature. 发生在具有MonoTouch 5.3的GLKit上,但是我认为问题可能是一般的OpenGL ES 2.0性质。

I have three faces, one of them red, one green and one blue, all with an alpha value of 1.0, so they should be opaque. 我有3张脸,其中一张是红色,一张绿色和一张蓝色,所有的alpha值为1.0,因此它们应该是不透明的。 When they are rendered on the black background, everything is okay. 当它们在黑色背景上渲染时,一切正常。 If the green face is in front of the others, everything is okay as well. 如果绿色的脸在其他人的面前,那么一切都还可以。 But if 但是如果

  • the red face is in front of the green 红色的脸在绿色的前面
  • or the blue face is in front of one of the others 或蓝色的脸在另一个人的面前

the foreground color is not rendered, but the background face is fully visible. 不会渲染前景色,但是背景面是完全可见的。 This seems to be some kind of blending effect, but I don't see anything special in my code, and I have tried out several things like glBlendFunc , but it didn't change anything. 这似乎是某种混合效果,但是我的代码中看不到什么特别的东西,并且我已经尝试了glBlendFunc类的几件事,但是它并没有改变任何东西。

I could post my code, but since the code is quite simple, I thought perhaps someone knows the answer immediately. 我可以发布代码,但是由于代码非常简单,所以我认为也许有人会立即知道答案。

Update: As this seems to be a Depth-Sorting issue, here are some important parts of the code: 更新:由于这似乎是一个深度排序问题,因此以下是代码的一些重要部分:

        var aContext = new EAGLContext(EAGLRenderingAPI.OpenGLES2);
        var view = this.View as GLKView;
        view.Delegate = new GenericGLKViewDelegate(this);
        view.Context = aContext;

        view.DrawableColorFormat = GLKViewDrawableColorFormat.RGBA8888;
        view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format16;
        view.DrawableMultisample = GLKViewDrawableMultisample.Sample4x;

here is the DrawInRect method: 这是DrawInRect方法:

        _baseEffect.PrepareToDraw();

        GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

        GL.EnableVertexAttribArray((int)GLKVertexAttrib.Position);
        GL.EnableVertexAttribArray((int)GLKVertexAttrib.Color);

        GL.VertexAttribPointer((int)GLKVertexAttrib.Position, 3, VertexAttribPointerType.Float, false, 0, _squareVertices);
        GL.VertexAttribPointer((int)GLKVertexAttrib.Color, 4, VertexAttribPointerType.UnsignedByte, true, 0, _squareColors);

        GL.DrawArrays(BeginMode.TriangleStrip, 0, 9);

        GL.DisableVertexAttribArray((int)GLKVertexAttrib.Position);
        GL.DisableVertexAttribArray((int)GLKVertexAttrib.Color);

I tried every possible combination of ColorFormat , DepthFormat and Multisample , but it's still the same. 我想每一个可能的组合ColorFormatDepthFormatMultisample ,但它仍然是相同的。

Solution: 解:

I was missing some calls to enable the depth buffer, these calls were missing in the ViewDidLoad method: 我缺少一些启用深度缓冲区的调用,这些调用在ViewDidLoad方法中丢失:

        GL.ClearDepth(30);
        GL.Enable(EnableCap.DepthTest);
        GL.DepthFunc(DepthFunction.Lequal);

This does not sound like a blending issue- rather a depth-sorting issue. 这听起来不像是一个混合问题,而是一个深度排序问题。

Is the depth buffer enabled? 是否启用深度缓冲区? Are you clearing it with each frame? 您是否在每一帧都清除它?

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

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