This topic is now archived and is closed to further replies.



Recommended Posts

Lemme make this clear. Say, i''m gonna make something transparent so that I can see things underneath it and i can also control the level of transparency. Well..... this is what you call Alpha Blending. But suppose i aint got no graphics library and nothing and I start coding right from the scratch in DOS. Could anyone plz tell me how do i do it in pixel levels. Plz dont go about saying "Use directx, use ARGB colors n make your polygons alpha blended." I want to know what exactly happens at pixel level when u Alpha Blend. Thanks guys........

Share this post

Link to post
Share on other sites
i believe it adds the color values together... for example, say this is your graphics:

graphic alphaBlt result
1 2 3 4 1 0 1 0 2 2 4 4
1 2 3 4 + 0 1 0 1 = 1 3 3 5
1 2 3 4 2 0 2 0 3 2 5 4
1 2 3 4 0 2 0 2 1 4 3 6

of course, the color values for pixels in a graphic aren''t little integers like this example, they are 24-bits or whatever...
as far as the level of transparency, you have to figure out the ratio of the alpha pixels to add to the base graphic. i think. don''t quote me though

--- krez (

Share this post

Link to post
Share on other sites
Assuming we have 8 bits per color component (RGB) and we elect to also have 8 bits for transparency/alpha (which conveniently gives us 32-bit color specifications). If 0 is perfectly transparent and 1 is opaque, then the alpha values from 0 to 255 represent the transparency ratios from 0.0 to 1.0.

When we look at a transparent object, we see what lies behind it tinted by its own color. How much of its color we see is the alpha value. Assuming black is our transparency color (absence of color) and white is perfect opacity, then the alpha value indicates what shade from black to white to blend with our pixel color:

dest_r = (src_r + alpha) / 2;
dest_g = (src_g + alpha) / 2;
dest_b = (src_b + alpha) / 2;

The reason we divide by 2 is that the weighted average of two quantities of equal scale (range) is a simple average. Since we add the same amount to each of the components, this has the effect of blending in a shade of grey/white.

Since we''ve set our pixel to be transparent, we need to mix it in with whatever lies logically beneath it. We use the weighted average again (and realize that the underlying pixel may itself be transparent). Picture a scene where you are looking at a distant object through several panes of tinted glass... you quickyl start to realize the potential order of magnitude of such work (e.g., a greenhouse without the foilage).

In any case, those are the fundamental principles. You can find tons of more specific information on the web (and I could look some up, but I''m tired).

Share this post

Link to post
Share on other sites
If 0 <= alpha <= 1 then:

base.r = base.r * (1 - alpha) + image.r * alpha;
base.r = base.g * (1 - alpha) + image.g * alpha;
base.r = base.b * (1 - alpha) + image.b * alpha;

If you''re using a paletted mode then this becomes more complex....

Share this post

Link to post
Share on other sites