PDA

View Full Version : glDrawPixels and transparency



12-27-2005, 09:45 PM
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.

Thanks,
Gubber

dmy
12-28-2005, 01:14 AM
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.

12-28-2005, 08:49 AM
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

dmy
12-29-2005, 06:09 AM
as i said, you need to have alpha bits in your image to use alpha testing.