title: Strange blending effect in OpenGL ES 2.0 using GLKit
body: <p>This happens on GLKit with MonoTouch 5.3, but I think the problem may be of general OpenGL ES 2.0 nature.</p>
  
  <p>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. 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</p>
  
  <ul>
  <li>the red face is in front of the green</li>
  <li>or the blue face is in front of one of the others</li>
  </ul>
  
  <p>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 <code>glBlendFunc</code>, but it didn't change anything.</p>
  
  <p>I could post my code, but since the code is quite simple, I thought perhaps someone knows the answer immediately.</p>
  
  <p><strong>Update:</strong> As this seems to be a Depth-Sorting issue, here are some important parts of the code:</p>
  
  <pre><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;
  </code></pre>
  
  <p>here is the DrawInRect method:</p>
  
  <pre><code>        _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);
  </code></pre>
  
  <p>I tried every possible combination of <code>ColorFormat</code>, <code>DepthFormat</code> and <code>Multisample</code>, but it's still the same.</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>I was missing some calls to enable the depth buffer, these calls were missing in the <code>ViewDidLoad</code> method:</p>
  
  <pre><code>        GL.ClearDepth(30);
          GL.Enable(EnableCap.DepthTest);
          GL.DepthFunc(DepthFunction.Lequal);
  </code></pre>