masking/blending problems

I’ve been trying to make a single color of my image maps transparent. The first approach was the one I’ve seen recommended many times on this board - add an alpha channel to the image, and set the pixels with the desired color to 0 alpha, and the rest of the pixels to 255 (using bytes). However, this does not give correct results if the texture is filtered using anything other than GL_NEAREST, GL_NEAREST. If I build mipmaps, or use GL_LINEAR filtering, it appears that the image resampling causes small areas of the color that should be transparent to become semi-opaque, and so the image is displayed with a faint outline. I’m assuming that the texture filter is interpolating the alpha values of the image and creating values between 0 and 255. This is noticeable with both blending using source alpha, or when using alpha testing instead of blending.

The other approach was using NeHe’s masking technique, with one texture for the image, and another for the alpha mask. This works fine with all texture filtering, but takes 2 passes and is a little clumsy, so I don’t really want to use it.

Anyone got any ideas ??

Your theory about filtering and the alpha channel is correct.

Concerning the separate alpha texture. You don’t need two passes. Simple multitexturing can be used to combine the two textures in one pass. Setting the color texture to a nice linear filtering, and the alpha channel to nearest filtering should work. Then use the GL_ADD (assuming either GL_ARB_texture_env_add extension or OpenGL 1.2) texture environment function to add them together. Then use the alpha function to reject/accept fragments, as usual.

try to use alphamasking like:
glAlphaFunc(GL_EQUAL, 0);
this will only draw pixels with alpha value of 0 (ZERO) , or play a bit with the function like
glAlphaFunc(GL_GREATER, 0.5f);
draws only pixel with alpha values greater than 128 …
and dont forget to enable alphatest:

but maybe you want to resample your alphamap by yourself, and then use glTexSubImage with some commands which disables writing to the r,g and b components (dont know commands doing this), something like the glColorMask for the ColorBuffers …

or you can try to change the pixel-transfer-options, but you have to try if they affect mipmap generation:
void glPixelTransferf(GL_ALPHA_SCALE, 2.0f/or bigger/);
this should let alpha values of 0 become 0 again and other values will be 1.0f(=255) dependent on the scale-factor