glDrawPixels and transparency

Hey Guys,

I have been trying to load a 24 bit .bmp into the frame buffer, and a 24 bit image does not contain alpha values, but I want the colour (say white) not to be drawn so that i can have transparency. I can not figure out how to do this without reordering me BGR data to RGB and then adding an ALPHP value at the end and then using gjDrawPixel in format GL_RGBA. This solution seems to be suboptimal. I tried glDrawPixel with GL_BGR_EXT and GL_ALPHA to draw the parts sepratley(after generating my own alpha values based on the image). Ontop of that I tried using glColorMask, to no avail, and glBlendFunc, but I could just not get it to work(yes I used glEnable(GL_BLEND)).

I would really appriciate any ideas on how to properley use glDrawPixels, glColorMask, glBlendFunc, and/or other functions to make this work.


since you need to have at least one bit wich says “draw this, skip this” with sufficent generality to allow you to decide wich pixel should be drawn, you have to include at least one bit for alpha…
as far as i know, the kind of color masking you need (basically color keying) is not possible with basic opengl: with shaders you can do anything you like but it is somewhat advanced stuff.

glDrawPixel take into account alpha testing (well, the pipeline does, really) so if you enable it, you can draw your sprite, once you have alpha in it:

glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_GREATER, 0.5 );
glDrawPixels( ... GL_RGBA ... );

another road is to use the stencil buffer:
you have two pixmaps, one RGB and a mask, then you do something like this:

glDrawPixels( ... GL_STENCIL_INDEX ... );
glEnable( GL_STENCIL_TEST );
glStencilFunc( ... );
glDrawPixels( ... GL_RGB ... );

but, you need a stencil buffer with this approach… i would go for the RGBA way.

i tried the alpha test thing, but since the input has no alpha values its putting all the pixels in the wrong places, ie, the data im sending only has BGR so it cant draw BGRA

as i said, you need to have alpha bits in your image to use alpha testing.