Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Additive Blending?

This thread is locked; no one can reply to it. rss feed Print
Additive Blending?
Kikaru
Member #7,616
August 2006
avatar

Well, I was thinking, and worked this out:

int blend(int col1, int col2, int fade)
{
     int ncol;
     int inv_fade = 255 - fade;
     ncol = ((col1*fade)+(col2*inv_fade)) >> 8;
     return ncol;
}

Is this how you do additive blending? ???

Jonatan Hedborg
Member #4,886
July 2004
avatar

I would guess more like:

int blend(int source, int dest, int fade) {
  int ncol;

  ncol = MIN(255, makecol(
    (getr(source)*fade)>>8)+getr(dest), 
    (getg(source)*fade)>>8)+getg(dest), 
    (getb(source)*fade)>>8)+getb(dest)
  );

  return ncol;
}

But more to the point; why? There is already an additive blending function in allegro.

EDIT: fixed my code :)

Kitty Cat
Member #2,815
October 2002
avatar

int blend(int col1, int col2, int fade)
{
     return MIN(((col1*fade)+col2, 255);
}

Assuming single-component 0..255 values.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Jonatan Hedborg
Member #4,886
July 2004
avatar

Don't you have to do something funky with fade, assuming 0..255 range?

Kitty Cat
Member #2,815
October 2002
avatar

Oh, right.

int blend(int col1, int col2, int fade)
{
     return MIN( ((col1*fade)>>8) + col2, 255);
}

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Kikaru
Member #7,616
August 2006
avatar

I didn't know there was one in Allegro. Well, Thanks! :)

Ceagon Xylas
Member #5,495
February 2005
avatar

Fblend's much, much faster than the allegro blending routines. Linkage

Paul whoknows
Member #5,081
September 2004
avatar

Is there a good reason not to merge Fblend with allegro?

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Kitty Cat
Member #2,815
October 2002
avatar

Allegro wouldn't be able to take advantage of FBlend's improvements due to API design differences.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

HardTranceFan
Member #7,317
June 2006
avatar

I'm keen to try out FBlend. However, I'm very much in the dark on how to use it. I assume I need to compile allegro with FBlend in order to get it working. Question is, how do I do this? I downloaded the Allegro 4.2.1 binary files, and I'm not familiar with command line compilations using makefiles.

Do I need to recompile allegro with FBlend, or is there a binary version which I can bung onto my program?

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Ceagon Xylas
Member #5,495
February 2005
avatar

There's a binary version here. Just link the library, copy the headers, and you're ready to go. ;D

It's extremely easy to use. Even easier than allegro's blender routines. Everything you need to know is in the docs.

Neil Walker
Member #210
April 2000
avatar

I agree, fblend is much faster and much simpler.

There's no need for setting up the blender types, you just call for bitmaps:

fblend_add(src,dst,x,y,factor)
fblend_trans(src,dst,x,y,factor)

and for primitives theres similar ones, e.g. fblend_rect_add, fblend_rect_trans.

There's also a few others that may or may not be useful like 2x stretch.

there's also an undocumented fblend_fade_to_color,which does exactly what it says :)

though I can't remember if this works or not.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

HardTranceFan
Member #7,317
June 2006
avatar

Ceagon Xylas: Thanks. :)

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Go to: