How to make some color in texture transparent ?

I mean for instance i load texture and i would like to make every purple color transparent. How to do it. I would like to load bmp file.

The best way is to use a ALPHA mask to indicate what areas are transparent.

One of the problems with BMP files is they do not support an alpha channel, but there are ways to work around it.

The easy way is to convert the BMP files to the TGA file format, which supports an ALPHA channel. Then with a paint program like Paint shop pro make a ALPHA mask to make areas transparent.

nehe.gamedev.net has a tutor on ALPHA mask for transparent areas. I think it is tutor # 33. I think he shows how to use both TGA and BMP file with Apha mask, though BMP takes more work.

Originally posted by jirkamelich:
I mean for instance i load texture and i would like to make every purple color transparent. How to do it. I would like to load bmp file.

You can also create the alpha mask programmatically when you load in your BMP. Pseudocode for this would look something like so…

BMPData pBMP = GetBMPData(“file.bmp”);
unsigned char *pRGBAData = new unsigned char[pBMP->width * pBMP->height * 4];

for (int y=0;yheight;y++)
{
for (int x=0;xwidth;x++)
{
int index = x+ypBMP->width;
unsigned char
pRGBPixel = pBMP->Data[index3];
unsigned char
pRGBAPixel = pRGBAData[index*4];

  pRGBAPixel[0] = pRGBPixel[0];
  pRGBAPixel[1] = pRGBPixel[1];
  pRGBAPixel[2] = pRGBPixel[2];

  if (pRGBPixel is purple)
  {
     pRGBAPixel[3] = 0;
  }
  else
  {
     pRGBAPixel[3] = 255;
  }

}
}

Also, I think the BMP specification does allow for an alpha channel, but it is a rarely used feature. It’s been awhile since I took a look at that. Not even sure offhand what programs you could use to save a BMP with an alpha channel.

[This message has been edited by Deiussum (edited 12-27-2002).]