hi color pixel blending
I am writing a 2D 16 bpp arcade game, It uses the allegro graphics lib.
I have certain sprites (explosions, glows) which are drawn against a
black background, when I blit these against a different background the
sprite''s edges do not blend with the background and the sprite
looks bad, I am not talking about anti-aliasing here, I am talking
about reading rgb of source pixel and combining it with rgb of destination
pixel to make it look natural (the way it has been drawn against black
background).
for achieving this I got some helpful code from chris''s page
which did alpha and additive blending, the problem is if I additively blend
my sprite with background it looks fine against dark backgrounds but
looks totally bright against bright backgrounds.the problem with alpha
blending is that it completely kills intensity of colors.
equation for additive blending is r3=r1+r2; if (r3>255) r3=255;
equation for alpha blending is
alpha=(2*r1+3*g1+b1)/6;
r3=((r1*alpha)+(r2*(255-alpha)))/256;
equation for screen blending is r3 = r1 + r2 - ((r1*r2) / 100);
where r1 is sprite color, r2 is background color, r3 is result (blended) color.
The right way to do this was while drawing the image to use a additional
alpha channel which controlled the transparency per pixel and to save
this image in a format which supported transparency like tga.
but due to lack of vision all graphics have been drawn and saved as
windows bitmap files.
Now I cant seem to blend them right with the backgrounds.
my test program will make it clear, please download it from
http://www.geocities.com/lazy_coder/code/all.zip (350k)
or
if you have allegro for msvc installed
http://www.geocities.com/lazy_coder/code/src.zip (70k)
the page is http://www.geocities.com/lazy_coder/index.htm
if you can help me I will be most obliged and will give full
credit.
Please try to mail me directly as I am not subscribed to the mailing list.
Deepak T (coolbool@gmx.net)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement