title: Alpha Blending textures on two different passes using GLSL
body: <p>What I have is a set of 9 squares in a 3x3 grid being rendered for testing this blending function.  Here's the idea.</p>
  
  <p>On Pass 1:  </p>
  
  <ul>
  <li>Bind texture1 (dirt)</li>
  <li>Render the squares using tex1 = Dirt</li>
  </ul>
  
  <p>On Pass 2:</p>
  
  <ul>
  <li>Bind texture2 (letter)  </li>
  <li>Render the same squares using tex2 = Letter W</li>
  </ul>
  
  <p>This is for an in-game editor. We want to be able to change the color of letters from a text atlas as they are typed.  The shader is supposed to check the alpha value of the fragment from the texture.  Anything that is not equal to 0 (i.e. Visible) should be changed to the desired color that is passed into the shader as an attribute.  </p>
  
  <pre><code>//Draw all Squares
  
  glBindTexture(GL_TEXTURE_2D, textureID1);   //Dirt Texture
  
  for (int Index = 0; Index &lt; 9; Index++)
  {
  //Pass in Vertex Positions...
  //Pass in UV's...
  glDrawArrays(GL_TRIANGLES, 0, 6); // From index 0 to 6 -&gt; 2 triangle
  }
  
  //Redraw Squares with letter texture bound.
  
  glBindTexture(GL_TEXTURE_2D, textureID2);  //Letter Texture
  
  glVertexAttrib3f(2,255,0,0);  //Desired Color of letter, passed to shaders.
  
  glEnable(GL_ALPHA_TEST);
  glAlphaFunc(GL_GREATER,0.05f);  //Anything with alpha &lt; 0.05 is discarded.
  
  //Draw all Squares
  for (int Index = 0; Index &lt; 9; Index++)
  {
     //Pass in Vertex Positions...
     //Pass in UV's...
  glDrawArrays(GL_TRIANGLES, 0, 6); // From index 0 to 6 -&gt; 2 triangle
  }
  
  glDisableVertexAttribArray(0);
  glDisableVertexAttribArray(1);
  glDisable(GL_ALPHA_TEST);
  
  //Draw blue vertex dots...etc...
  </code></pre>
  
  <p>Here's a picture showing the source images, and the output of 2 slightly different Fragment shaders. Along with the desired result.</p>
  
  <p><a href="http://img84.imageshack.us/img84/7376/stackexchangealphablend.jpg" rel="nofollow">Image Sources, with Frag Shaders and Desired Result</a>  </p>
  
  <p>The textures are loaded, both have alpha channels (GL_BGRA, Targas). I'm using GL_NEAREST as MIN/MAG FILTERS.</p>
  
  <p>The odd thing is, this shader works for me if I use 99% white (i.e. 254) in the alpha channel of the LETTER TEXTURE and fails when I use full white (i.e. 255).</p>
  
  <p>I've tried enabling GL_BLEND and using various BlendFunc's, but they don't seem to work.</p>
  
  <p>I guess the question is.  Without using a multitexture shader, and without rendering to an FBO, is this the right way to do this sort of blending?</p>