I’ve got an 8bit image, with 0 being the transparent color index (256 color palette, each byte value is an offset into an RGB color lookup table, just in case anyone didn’t know…). I’ve got this image, 16x16, that resembles (rather crappily) the face of a person. My problem is, when i display the image, everything is fine, except that the top line has some artifacts…it appears that there are some black looking pixels in it, when that whole line should be transparent.
Internally, in my GLubyte array which contains the graphics data, I have translated the color table index into an RGBA value. So I lookup the requested color, check if that index was the transparent index, and if so, set the alpha component to 0. If it’s not transparent, I set alpha to 255. So now there are 4 bytes (RGBA) per pixel describing this image.
So here’s how I’m setting up the texture and then display list:
glGenTextures(1, &tex_id);
glBindTexture(GL_TEXTURE_2D, tex_id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, gfx_data);
dl = glGenLists(1);
glNewList(dl, GL_COMPILE);
glScaled(16, 16, 0);
glBindTexture(GL_TEXTURE_2D, tex_id);
glBegin(GL_QUADS);
glTexCoord2i(0, 1); glVertex2i(-1, -1);
glTexCoord2i(0, 0); glVertex2i(-1, 1);
glTexCoord2i(1, 0); glVertex2i(1, 1);
glTexCoord2i(1, 1); glVertex2i(1, -1);
glEnd();
glEndList();
Perhaps the problem is with the values GL_LINEAR and/or GL_LINEAR_MIPMAP_NEAREST? Oh ya, and in my code loop I’ve got:
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
before drawing the above image (and turn off texture/alpha when done drawing). I’ve also got the following set up before any drawing was done:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Thanks for your help, I really appreciate it.