簡體   English   中英

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

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

發生在具有MonoTouch 5.3的GLKit上,但是我認為問題可能是一般的OpenGL ES 2.0性質。

我有3張臉,其中一張是紅色,一張綠色和一張藍色,所有的alpha值為1.0,因此它們應該是不透明的。 當它們在黑色背景上渲染時,一切正常。 如果綠色的臉在其他人的面前,那么一切都還可以。 但是如果

  • 紅色的臉在綠色的前面
  • 或藍色的臉在另一個人的面前

不會渲染前景色,但是背景面是完全可見的。 這似乎是某種混合效果,但是我的代碼中看不到什么特別的東西,並且我已經嘗試了glBlendFunc類的幾件事,但是它並沒有改變任何東西。

我可以發布代碼,但是由於代碼非常簡單,所以我認為也許有人會立即知道答案。

更新:由於這似乎是一個深度排序問題,因此以下是代碼的一些重要部分:

        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;

這是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);

我想每一個可能的組合ColorFormatDepthFormatMultisample ,但它仍然是相同的。

解:

我缺少一些啟用深度緩沖區的調用,這些調用在ViewDidLoad方法中丟失:

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

這聽起來不像是一個混合問題,而是一個深度排序問題。

是否啟用深度緩沖區? 您是否在每一幀都清除它?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM