0

I'm trying to make a program showing a red rotating cube in the background, overlayed with a textured quad.

The texture is a simple 24-bit bitmap of the words "Hello World" in black over a white background. I want the white background to be transparent so that the cube can be seen behind the overlay. The image loader checks the value of each pixel and adds the relevant alpha value to convert the image into a 32-bit bitmap.

At the moment, my program displays the overlay with black text but a red background, same colour as the cube. Below is the code used for the initial texture set up:

if (bitmap->Load("test.bmp")) {
   glGenTextures(1, &texture);
   glBindTexture(GL_TEXTURE_2D, texture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap->GetWidth(), bitmap->GetHeight(),
      0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap->GetPixelData());
}

And this is the whole of my display function, in case anything is interfering with anything else.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40, 1, 0.1, 27.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glTranslatef(0.0, 0.0, -1.1);
glRotatef(angle, 1.0, 1.0, 0.0);
glutSolidCube(0.1);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 640, 480, 0.0, -1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_CULL_FACE);

glClear(GL_DEPTH_BUFFER_BIT);

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, texture);

glBegin(GL_QUADS);
   glTexCoord2d(0.0, 0.0); glVertex2f(0.0, 0.0);
   glTexCoord2d(1.0, 0.0); glVertex2f(320.0, 0.0);
   glTexCoord2d(1.0, 1.0); glVertex2f(320.0, 240.0);
   glTexCoord2d(0.0, 1.0); glVertex2f(0.0, 240.0);
glEnd();

glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);

glFlush();
glutSwapBuffers();
genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

0

The default texture environment is GL_MODULATE which mixes in the current color (red from your cube) with the incoming texel value.

Switch to GL_DECAL or do a glColor3ub(255,255,255) before you render your text.

genpfault
  • 51,148
  • 11
  • 85
  • 139