View Full Version : making blue transparent in a .bmp
06-24-2001, 10:36 PM
I am new at opengl and was wondering:
I want to take a bitmap and chang it so it is rgba instead of rgb. Whever it is 0,0,255(pure blue) I want the a to be set to transparent. How exactly do i do this?
Change the alpha values for the pixels with that color value and use alpha testing.
06-24-2001, 11:49 PM
Ummmm, use 0.0, 0.0, 1.0 type colors, not indexed colors. This way just enable Blending
and do glColor4f(0.0, 0.0, 1.0, alpha_value);
06-25-2001, 07:02 AM
So you saying that if I do:
and than draw the rectangle
the blue will be transparent? Someone should make a utility for dumb people like me that converts it to a new kind of bitmap that suports the alpha channel.
[This message has been edited by bobertperry (edited 06-25-2001).]
06-25-2001, 08:04 AM
What you need to do is, when you are loading the texture, convert it to RGBA. If the texel is 0, 0, 255, then make its alpha 0. If it is not that color, make its alpha 255.
Afterwards, do call glEnable for the alpha test, but don't turn blending on. You will need to set glAlphaFunc so that it culls fragments with alpha less than 0.5 (128).
06-25-2001, 08:20 AM
That code will not change blue to transparent. However writing a function to convert an RGB image to an RGBA image is quite trivial. Just read in the pixels, test each one to see if it matches the mask color and if it does set the alpha component of the destination pixel to 0 else set the alpha component to 255 (assuming unsigned bytes are being used), and just copy over the color components verbatum. For example:
typedef unsigned char byte;
rgba_t *RGBtoRGBA(rgb_t *src, unsigned int numpixels)
rgba_t* dst=new rgba_t[numpixels];
if(!dst) return 0;
for(unsigned int i=0;i<numpixels;i++,tdst++,src++)
if(!src->r && !src->g && src->b==255)
[This message has been edited by DFrey (edited 06-25-2001).]
06-25-2001, 09:24 PM
AH! I see now what you wanted! Sorry, my suggestion is totally wrong then.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.