drawing with white as transparent


I’ve been trying to draw images where the white bit is not drawn, and using the following code I get the white bits but not the coloured bits, but every other way I can combine this code in different orders gives me all black or no removal of white. Please, how do I do this to get rid of just the white.

glRasterPos2i(100, 100);
glDrawPixels(myImage.GetWidth(),myImage.GetHeight(), GL_BGR_EXT, GL_UNSIGNED_BYTE, image);
glDrawPixels(myImage.GetWidth(),myImage.GetHeight(), GL_ALPHA, GL_UNSIGNED_BYTE, al);
glAlphaFunc(GL_NOTEQUAL, 0);

a similar question just somedays ago: post

opengl does not color-keying natively. maybe there’s an extension but i didn’t found it.

to draw sprites, the easier way is to add the alpha channel to your image, thus getting a RGBA image.

then, you enable alpha testing and draw your pixmap with glDrawPixels as usual.

you can choose to generate the alpha bitplane offline (ie outside your application, with photoshop/paint shop pro/whatever) or do it online, inside your app: while loading the RGB image, you check the incoming color, if it’s white, you set alpha=1 for that pixel, otherwise you set alpha=0.

i’d go for the last approach.

thanks dmy