title: Opengl Texture Transparency .BMP
body: <p>I am drawing a polygon with texture on it as part of the HUD in my OpenGL program.</p>
  
  <pre><code>//Change the projection so that it is suitable for drawing HUD
  glMatrixMode(GL_PROJECTION);  //Change the projection
  glLoadIdentity();
  glOrtho(0, 800, 800, 0, -1, 1);  //2D Mode
  glMatrixMode(GL_MODELVIEW);  //Back to modeling
  glLoadIdentity();
  
  //Draw the polygon with the texture on it
  glBegin(GL_POLYGON);
  glTexCoord2f(0.0, 1.0); glVertex3f(250.0, 680, 0.0);
  glTexCoord2f(1.0, 1.0); glVertex3f(570.0, 680, 0.0);
  glTexCoord2f(1.0, 0.0); glVertex3f(570.0, 800, 0.0);
  glTexCoord2f(0.0, 0.0); glVertex3f(250.0, 800, 0.0);
  glEnd();
  
  //Change the projection back to how it was before
  glMatrixMode(GL_PROJECTION);  //Change the projection
  glLoadIdentity();
  gluPerspective(45.0, ((GLfloat)800) / GLfloat(800), 1.0, 200.0);  //3D Mode
  glMatrixMode(GL_MODELVIEW);  //Back to modeling
  glLoadIdentity();
  </code></pre>
  
  <p>The problem is that I can't get the "box" around the image to blend with the background. I opened the image (.bmp) in Photoshop and deleted the pixels around the image that I want displayed, but it still draws the whole rectangular image. It colors the pixels that I deleted with the last color that I used with glColor3f(), and I can get the whole image to become transparent, but I only want the pixels that I deleted in Photoshop to be transparent.
  Any suggestions?</p>
  
  <p>Properties that I am using for the textures:</p>
  
  <pre><code>glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, TextureList[i]-&gt;getSizeX(), TextureList[i]-&gt;getSizeY(), GL_RGB, GL_UNSIGNED_BYTE, TextureList[i]-&gt;getData());
  </code></pre>
  
  <p>Here's an image of my program. I'm trying to get the white box to disappear, but as I decrease the alpha with glColor4f(), the whole image fades instead of just the white box. <br/>
  img607.imageshack.us/img607/51/ogly.png</p>
  
  <p>Code that loads a texture from file:</p>
  
  <pre><code>texture::texture(string filename)
  {
  // Routine to read a bitmap file.
  // Works only for uncompressed bmp files of 24-bit color.
  // Both width and height must be powers of 2.
  unsigned int size, offset, headerSize;
  
  // Read input file name.
  ifstream infile(filename.c_str(), ios::binary);
  
  // Get the starting point of the image data.
  infile.seekg(10);
  infile.read((char *) &amp;offset, 4);
  
  // Get the header size of the bitmap.
  infile.read((char *) &amp;headerSize,4);
  
  // Get width and height values in the bitmap header.
  infile.seekg(18);
  infile.read( (char *) &amp;sizeX, 4);
  infile.read( (char *) &amp;sizeY, 4);
  
  // Allocate buffer for the image.
  size = sizeX * sizeY * 24;
  data = new unsigned char[size];
  
  // Read bitmap data.
  infile.seekg(offset);
  infile.read((char *) data , size);
  
  // Reverse color from bgr to rgb.
  int temp;
  for (unsigned int i = 0; i &lt; size; i += 3)
  { 
  temp = data[i];
  data[i] = data[i+2];
  data[i+2] = temp;
  }
  }
  </code></pre>