View Full Version : transparent color problem

05-07-2004, 11:00 AM
I've made a 2d game that displays sprites that are loaded from 24-bit windows bmp files. The problem is that I don't want to draw the black pixels surrounding the sprites. Right now I'm using blending and masks to display the sprites, but the sprites are still blending over one another. I want to get rid of the masking all together because it is twice the drawing than I should need. I simply want to tell opengl not to draw the black pixels in these bitmaps. I'm using the glDrawPixels function.

05-07-2004, 12:10 PM
If you set the "black pixels" to rgba 0,0,0,0 and use alpha testing, it would be okay with a single pass I think ?

Something like :


>> Right now I'm using blending and masks to display the sprites, but the sprites are still blending over one another.
What do you mean ?

05-07-2004, 01:02 PM
I forgot to say that I'm using RGB mode. The pixel data doesn't have any alpha data. I would have to some how covert all the pixel data from RGB to RGBA. To clear up what I have been doing: I first draw a mask, which is a black and white equivalent of the sprite bitmap, then I draw the sprite itself so it shows up correctly without the surrounding black pixels. I use blending so that what is black in the mask shows up on the sprite and what is white does not. Basically like this:
glDrawPixels(width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, mask);
glBlendFunc(GL_ONE, GL_ONE);
glDrawPixels(width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, sprite);

Using this method however I'm having to draw the sprite twice, which is a hinderence on performance. I thought it would have been simple to call glDrawPixels and have it ignore the black pixels. Is their a way to do this without using alpha testing?

05-08-2004, 01:28 AM
You do have alpha data, that's your sprite mask.

Simplest thing to do would be to use an RGBA context, RGBA sprites, and the alpha test.

Then, where the sprite's mask is white, set the alpha to 1.0, and where it's black, set it to 0.0 (assuming that a white pixel in the mask indicates that you want to draw the corresponding pixel in the sprite).

Then you can use the alpha test, and may be able to disable blending altogether...

05-09-2004, 10:32 AM
Thanks, I finally got the alpha testing to work. I'm sure it will be faster but I'll do some tests anyway.