Skip to main content
GameDev.net gamedev.net
🔒 Locked

Transparency with bitmaps

Started by Zyroth Dec 10, 2002 at 12:37 PM 2 replies 300+ views
Original Post
Zyroth
Zyroth
How would you do transparency with bitmaps. They don''t have a value for alpha blending for the level of transparency for each pixel. So how is it done?
Rob Loach
Rob Loach
I assume this is for 2D sprites and masks.

You can get the RGB values of each pixel of both source and destination and then combine them using this:


r = (((100 - Percentage) * r1) + (Percentage * r2)) / 100
g = (((100 - Percentage) * g1) + (Percentage * g2)) / 100
b = (((100 - Percentage) * b1) + (Percentage * b2)) / 100

Note: n1 is the source, n2 is the destination, and n is the final pixel colour.



But I find that slow to do with EVERY pixel.

I like to do something like a filter of it. Something that looks like this:

Instead of drawing all pixels like this:

11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111



You would only draw some like this... (This is for 50%)

10101010101010101010
01010101010101010101
10101010101010101010
01010101010101010101
10101010101010101010
01010101010101010101


- Rob Loach
OverTech Technologies
----------
"I don''t know half of you half as well as I should like; And I like less than half of you half as well as you deserve."
- Bilbo Baggins
Rob Loach [Website] [Projects] [
Zyroth
Zyroth
Ok, I understand that part.

But where do you get the percentage. In some file types they actually store the information for alpha blending.

But bitmaps don''t do that. I kind of wanted to do partial transparencies. So do I have to store that info in another file?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.