Additive blending

Hi,

I use both SDL and sdl_gfx and I’m wondering if anyone has an example of
blitting with RLE, alpha channel using additive blending. This is kinda
going to be used for special effects and all things glowy.

I’m not an experienced programmer and I am using blitzmax, which isn’t
C++ with the SDL dll. So please be gentle :slight_smile:

Thanks in advance!

To get Additive blending in SDL you have to write you own funktion which
does this for you.
I have written an funktion but sadly it is very slow and i dont know how to
optimize it.
Also i think additive blending should be a part of SDL.

Here of how it works.
You need an source and an destionation alpha component
here the pseudo code

uint8 src_alpha, uint8 dst_alpha
float f_scr = scr_alpha / 255;
float f_dst = dst_alpha / 255;

for( int i=0;i < hight;i++)
{
for( int j=0; j < width ; j++)
{
u8 sR,sG,sB; // color value from the source image
u8 dR,dG,dB; // color value from the destination image

     GetPixelValueFromSource( sR,sG,sB ,j,i);
     GetPixelValueFromDestionation( dR,dG,dB ,j,i);

    //calculate the final pixel which will be written to the

destionation image
uint 16 r,g,b;

    r = ( ( sR * f_src ) ) + ( (dR * f_dst ) ) ;
    g = ( ( sG * f_src ) ) + ( (dG * f_dst ) ) ;
    b = ( ( sB * f_src ) ) + ( (dB * f_dst ) ) ;

    //Saturat the value to fitt
   dR = r > 255 ? 255 : r;
   dG = g > 255 ? 255 : g;
   dB = b > 255 ? 255 : b;

   WritePixelBackToDestionationSurface(dR,dG,dB,j,i );

}

}

PS. i have an implemtion in c for additive blending.
Maybe some one want to optimized it.( Some MMX or SSE :smiley: )

2006/5/20, Rob :>

Hi,

I use both SDL and sdl_gfx and I’m wondering if anyone has an example of
blitting with RLE, alpha channel using additive blending. This is kinda
going to be used for special effects and all things glowy.

I’m not an experienced programmer and I am using blitzmax, which isn’t
C++ with the SDL dll. So please be gentle :slight_smile:

Thanks in advance!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hello Vardar,

Monday, May 22, 2006, 4:10:13 PM, you wrote:

VS> To get Additive blending in SDL you have to write you own funktion which
VS> does this for you.
VS> I have written an funktion but sadly it is very slow and i dont know how to
VS> optimize it.
VS> Also i think additive blending should be a part of SDL.

VS> Here of how it works.
VS> You need an source and an destionation alpha component
VS> here the pseudo code

VS> PS. i have an implemtion in c for additive blending.
VS> Maybe some one want to optimized it.( Some MMX or SSE :smiley: )

Remove the floats. Use fixed point math for this.
Also process more than one pixel at once. MMX/SSE solutions typically
process 4 pixels in one go.

Use pointers to read/write the pixels and don’t recalculate this
pointer every loop.

To be honest, blending like this is best done using OpenGL these days.–
Best regards,
Peter mailto:@Peter_Mulholland

Hello,

pygame added some additive blending modes recently.

Please have a look here:
http://rene.f0o.com/~rene/stuff/alphablit.c

They could be optimized a lot further. There’s no mmx, sse, 3dnow in
there, just C. It’s about 4x slower than SDLs alpha blit.On 5/20/06, Rob wrote:

Hi,

I use both SDL and sdl_gfx and I’m wondering if anyone has an example of
blitting with RLE, alpha channel using additive blending. This is kinda
going to be used for special effects and all things glowy.

I’m not an experienced programmer and I am using blitzmax, which isn’t
C++ with the SDL dll. So please be gentle :slight_smile:

Thanks in advance!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl