title: How can I get Alpha blending transparency working in OpenGL ES 2.0?
body: <p>I'm in the midst of porting some code from OpenGL ES 1.x to OpenGL ES 2.0, and I'm struggling to get transparency working as it did before; all my triangles are being rendered fully opaque.</p>
  
  <p>My OpenGL setup has these lines:</p>
  
  <pre><code>// Draw objects back to front
  glDisable(GL_DEPTH_TEST);
  
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
  glDepthMask(false);
  </code></pre>
  
  <p>And my shaders look like this:</p>
  
  <pre><code>attribute vec4 Position;
  uniform highp mat4 mat;
  attribute vec4 SourceColor;
  varying vec4 DestinationColor;
  
  void main(void) {
    DestinationColor = SourceColor;
    gl_Position = Position * mat;
  }
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>varying lowp vec4 DestinationColor;
  
  void main(void) {
    gl_FragColor = DestinationColor;
  }
  </code></pre>
  
  <p>What could be going wrong?</p>
  
  <p><strong>EDIT:</strong> If I set the alpha in the fragment shader manually to <code>0.5</code> in the fragment shader (or indeed in the vertex shader) as suggested by <a href="https://stackoverflow.com/a/17082037/328936">keaukraine below</a>, then I get transparent everything. <em>Furthermore</em>, if I change the color values I'm passing in to OpenGL to be floats instead of unsigned bytes, then the code works correctly.</p>
  
  <p>So it looks as though something is wrong with the code that was passing the color information into OpenGL, and I'd still like to know what the problem was.</p>
  
  <p>My vertices were defined like this (unchanged from the OpenGL ES 1.x code):</p>
  
  <pre><code>typedef struct
  {
    GLfloat x, y, z, rhw;
    GLubyte r, g, b, a;
  } Vertex;
  </code></pre>
  
  <p>And I was using the following code to pass them into OpenGL (similar to the OpenGL ES 1.x code):</p>
  
  <pre><code>glBindBuffer(GL_ARRAY_BUFFER, glTriangleVertexBuffer);
  glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * nTriangleVertices, triangleVertices, GL_STATIC_DRAW);
  glUniformMatrix4fv(matLocation, 1, GL_FALSE, m);
  glVertexAttribPointer(positionSlot, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, x));
  glVertexAttribPointer(colorSlot, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, r));
  glDrawArrays(GL_TRIANGLES, 0, nTriangleVertices);
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  </code></pre>
  
  <p>What is wrong with the above?</p>