mipmappnig and unwanted artifacts

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);



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);
glTexCoord2i(0, 1); glVertex2i(-1, -1);
glTexCoord2i(0, 0); glVertex2i(-1, 1);
glTexCoord2i(1, 0); glVertex2i(1, 1);
glTexCoord2i(1, 1); glVertex2i(1, -1);

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:


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:


Thanks for your help, I really appreciate it.

Mipmapping and index-based transparency don’t work well together, as when the subsampling is done the black texels will be mixed with the adjacent coloured texels.
The best solution is to store your textures with an alpha channel (use .tga or .png), and where the image is transparent use a similar colour to the colours in the image (e.g. put brown next to hair, and pink next to skin etc.)

you say there are some artifacts at the top of the texture ?
This sounds for me like a texture-wrap-bilinear-filtering problem.
I noticed that you don’t specify:


by default GL_REPEAT is set. this leads to some artifacts with non-tilebale textures because at the bottom of the texture the pixel are mixed with the first line.

… and if that’s the problem I think he would want GL_CLAMP_TO_EDGE and not GL_CLAMP which clamps to halfway into the border color.