title: How do I make textures transparent in OpenGL?
body: <p>I've tried to research this on Google but there doesn't appear to me to be any coherent simple answers. Is this because it's not simple, or because I'm not using the correct keywords?</p>
  
  <p>Nevertheless, this is the progress I've made so far.</p>
  
  <ol>
  <li>Created 8 vertices to form 2 squares.</li>
  <li>Created a texture with a 200 bit alpha value (so, about 80% transparent).</li>
  <li>Assigned the same texture to each square, which shows correctly.</li>
  <li>Noticed that when I use a texture with 255 alpha, it appears brighter.</li>
  </ol>
  
  <p>The init is something like the following:</p>
  
  <pre><code>glClearColor(0.0, 0.0, 0.0, 0.0);
  glShadeModel(GL_FLAT);
  glEnable(GL_DEPTH_TEST);
  
  glEnable(GL_CULL_FACE);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glGenTextures(1, textureIds);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  
  int i, j;
  GLubyte pixel;
  for (i = 0; i &lt; TEXTURE_HEIGHT; i++)
  {
      for (j = 0; j &lt; TEXTURE_WIDTH; j++)
      {
          pixel = ((((i &amp; 0x8) == 0) ^ ((j &amp; 0x8) == 0)) * 255);
          texture[i][j][0] = pixel;
          texture[i][j][1] = pixel;
          texture[i][j][2] = pixel;
          texture[i][j][3] = 200;
      }
  }
  
  glBindTexture(GL_TEXTURE_2D, textureIds[0]);
  
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  
  glTexImage2D(
      GL_TEXTURE_2D, 0, GL_RGBA,
      TEXTURE_WIDTH, TEXTURE_HEIGHT,
      0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
  </code></pre>
  
  <p>This is somewhat similar to the code snippet from page 417 in the book, <em>OpenGL Programming Guide</em>, and creates a check pattern.</p>
  
  <p>And then, the display function contains...</p>
  
  <pre><code>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_TEXTURE_2D);
  
  // Use model view so that rotation value is literal, not added.
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  
  // ... translation, etc ...
  
  glBindTexture(GL_TEXTURE_2D, textureIds[0]);
  glBegin(GL_QUADS);
  glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, +1.0, 0.0); // top left
  glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, -1.0, 0.0); // bottom left
  glTexCoord2f(1.0, 1.0); glVertex3f(+1.0, -1.0, 0.0); // bottom right
  glTexCoord2f(1.0, 0.0); glVertex3f(+1.0, +1.0, 0.0); // top right
  glEnd();
  
      // not neccecary to repeat, just good practice
  glBindTexture(GL_TEXTURE_2D, textureIds[0]);
  glBegin(GL_QUADS);
  glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, +1.0, -1.0); // top left
  glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, -1.0, -1.0); // bottom left
  glTexCoord2f(1.0, 1.0); glVertex3f(+1.5, -1.0, -1.0); // bottom right
  glTexCoord2f(1.0, 0.0); glVertex3f(+1.5, +1.0, -1.0); // top right
  glEnd();
  
  glFlush();
  glDisable(GL_TEXTURE_2D);
  
  glPopMatrix();
  
  SwapBuffers();
  </code></pre>
  
  <p>So, this renders a 2nd square in the background; I can see this but it looks like they're being blended with the background (I assume this because they are darker with 200 bit alpha than 255 bit) instead of the texture behind...</p>
  
  <p><img src="https://i.stack.imgur.com/ducoN.png" alt="Transparent textures not working"></p>
  
  <p>As you can see, no transparency... How can I fix this?</p>