Results 1 to 3 of 3

Thread: How to make some color in texture transparent ?

  1. #1
    Member Contributor
    Join Date
    Nov 2002
    Location
    Oirsbeek,Holland
    Posts
    69

    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.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to make some color in texture transparent ?

    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.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: How to make some color in texture transparent ?

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

    Code :
    BMPData pBMP = GetBMPData("file.bmp");
    unsigned char *pRGBAData = new unsigned char[pBMP->width * pBMP->height * 4];
     
    for (int y=0;y<pBMP->height;y++)
    {
       for (int x=0;x<pBMP->width;x++)
       {
          int index = x+y*pBMP->width;
          unsigned char* pRGBPixel = pBMP->Data[index*3];
          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).]
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. Replies: 2
    Last Post: 11-23-2011, 04:30 AM
  2. Make color transparent
    By Hylke Donker in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 03-23-2005, 06:44 AM
  3. How do I make the screen color transparent?
    By songeb in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-18-2001, 06:14 AM
  4. code for make black color of BITMAP (bmp) transparent...
    By MofuX in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 08-26-2001, 07:15 AM
  5. Make one spec. color appear as Transparent
    By Dingo in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 04-02-2001, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean