How do you make one color of a picture 100% transparent, and the rest 0% transparent.

Im using glDrawPixels to draw the pictures, and I heard, im supposed to use glBlendfunc, and a Black and White mask image, to do that, but i can’t figure the rest out.

Can someone give me a example, how to do that, and maybe explain glBlendFunc a little more in detail?


in this case why not just use the alpha test, I don’t know the exact syntax but just drop anything with an alpha not equal to 1. Its much easier than using a blend mask

Thanks for the tip, but it doesent work for me…

But I think there is no alpha values in my pic, because if i put glAlphaFunc(GL_EQUAL, 0) i get nothing drawn, but if i put glAlphaFunc(GL_EQUAL, 1), everything is drawn.

Im loading 24bit .bmps, and as far as i know only 32bit bitmaps have alpha values…

Now my question is:
Is there a way to set alpha values?

You’ll need to convert your RGB data to RGBA data, setting the A component based on the color.

The algorithm to convert from RGB to RGBA is fairly simple.

I load the pixeldata from myown format into a TBitmap, and then i use scanline to get it into pointer.
TBitmap has a PixelFormat property, it is set to 24bits(RGB), and i can set it to 32 bits(RGBA), but the alpha values dont get set. So how do i set the Alpha values to a Bitmap (in Delphi)?

If anyone has another solution to the initital question: (How do you make one color of a picture 100% transparent, and the rest 0% transparent.), please speak up.

Obviously the algorithm isn’t simple enough… Here’s pseudo code that sets the alpha to transparent for full white…

unsigned char* pRGB;
unsigned char* pRGBA;
int width;
int height;

pRGB = GetRGBDataFromImageHoweverYouWant();
width = GetWidthOfImageHoweverYouWant();
height = GetHeightOfImageHoweverYouWant();

pRGBA = new unsigned char[widthheight4];

for (int y=0;y<height;y++)
for (int x=0;x<width;x++)
// Set Red
pRGBA[(x+y*width)4] = pRGBA[(x+ywidth)3]
// Set Green
width)4+1] = pRGBA[(x+ywidth)3+1]
// Set Blue
width)4+2] = pRGBA[(x+ywidth)*3+2]

  if (pRGB[(x+y*width)*3] == 255 &&
      pRGB[(x+y*width)*3+1] == 255 &&
      pRGB[(x+y*width)*3+2] == 255)
      pRGBA[(x+y*width)*4+3] == 0;
      pRGBA[(x+y*width)*4+3] == 255;


[This message has been edited by Deiussum (edited 11-20-2003).]

I finnaly got it to work.

Thanks for your help!