View Full Version : glBlendFunc
11-17-2003, 08:56 AM
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?
11-17-2003, 11:56 AM
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
11-19-2003, 09:32 AM
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?
11-19-2003, 11:53 AM
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.
11-20-2003, 03:54 AM
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.
11-20-2003, 04:25 AM
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;
pRGB = GetRGBDataFromImageHoweverYouWant();
width = GetWidthOfImageHoweverYouWant();
height = GetHeightOfImageHoweverYouWant();
pRGBA = new unsigned char[width*height*4];
for (int y=0;y<height;y++)
for (int x=0;x<width;x++)
// Set Red
pRGBA[(x+y*width)*4] = pRGBA[(x+y*width)*3]
// Set Green
pRGBA[(x+y*width)*4+1] = pRGBA[(x+y*width)*3+1]
// Set Blue
pRGBA[(x+y*width)*4+2] = pRGBA[(x+y*width)*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).]
11-21-2003, 11:30 PM
I finnaly got it to work.
Thanks for your help!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.