Additive blending/Lightmaps

Hi, i currently have an additive blending effect which i added to my game, i
wrote a function to BLIT one surface over another using additive blending,
but it goes pixel by pixel in a double for loop… I was wondering if theres
any faster way, because lots of lighting lags the hell out of the engine.
Replies will be much appreciated. heres my code:

void eng::blit_lightmap(SDL_Surface *dest, int dstx, int dsty, int w, int h,
SDL_Surface *source, int srcx, int srcy)
{

int ix,iy;
Uint32 pix1,pix2;
for(iy=0;iy<h;iy++)
{
for(ix=0;ix<w;ix++)
{
if(dstx+ix<0||dsty+iy<0)continue;
if(dstx+ix>=dest->w||dsty+iy>=dest->h){continue;}
if(srcx+ix>=source->w||srcy+iy>=source->h){continue;}

  pix2=SDL_GetPixel(source,srcx+ix,srcy+iy);
  if(pix2)
  {
    pix1=SDL_GetPixel(dest,dstx+ix,dsty+iy);
    SDL_PutPixel(dest,dstx+ix,dsty+iy,lightencolors(pix1,pix2));
  }

}

}
}_________________________________________________________________
MSN 8: Get 6 months for $9.95/month. http://join.msn.com/?page=dept/dialup

Mike P. wrote:

Hi, i currently have an additive blending effect which i added to my
game, i wrote a function to BLIT one surface over another using
additive blending, but it goes pixel by pixel in a double for loop… I
was wondering if theres any faster way, because lots of lighting lags
the hell out of the engine. Replies will be much appreciated. heres my
code:

void eng::blit_lightmap(SDL_Surface *dest, int dstx, int dsty, int w,
int h,
SDL_Surface *source, int srcx, int srcy)
{

int ix,iy;
Uint32 pix1,pix2;
for(iy=0;iy<h;iy++)
{
for(ix=0;ix<w;ix++)
{
if(dstx+ix<0||dsty+iy<0)continue;
if(dstx+ix>=dest->w||dsty+iy>=dest->h){continue;}
if(srcx+ix>=source->w||srcy+iy>=source->h){continue;}

  pix2=SDL_GetPixel(source,srcx+ix,srcy+iy);
 if(pix2)
 {
   pix1=SDL_GetPixel(dest,dstx+ix,dsty+iy);
   SDL_PutPixel(dest,dstx+ix,dsty+iy,lightencolors(pix1,pix2));
 }

}

}
}

Look at some of the blit functions for code on how to do it quicker.

Hey, Atrix Wolfe [atrix2 at cox.net] was having the exact same problem!!..
Maybe you should contact him. I had replied that he should use a
different
method but it turned out to be a different kind of Bending (Alpha)… I
paste his own question here… (He may have solved it) Good Luck!!

Atrix Wolfe Wrote :>

I was wondering if there was a really quick way to do Additive blending
w/ or w/o light maps. Im not sure if im using the >correct terminology
so by additive blending i mean if i have a pixel on a surface that is
(50,25,150) and i want to
additive blend that with (30,30,30) i want to replace the pixel on the
surface with (80,55,180).

Right now i have a function that has a double for loop for x and y.
Inside it gets the source pixel
(either from the light map or using a constant) and then gets the dest
pixel, blends and writes the dest
pixel back.

I know i could do some optomizations like check and see if the source
pixel from the lightmap is completely
black not to do the blending, and also instead of having a double for
loop where it re-finds the pixel at
x,y i could get a pointer to the begining of the row on the outer loop
and just use the pointer in the inner
loop, but apart from that, is there any real good techniques to do
this?

Thanks a bunch!
Atrix

Juan Ignacio Carniglia - Programmer - Buenos Aires, Argentina.> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On
Behalf Of Mike P.
Sent: Saturday, August 23, 2003 11:51 PM
To: sdl at libsdl.org
Subject: [SDL] Additive blending/Lightmaps

Hi, i currently have an additive blending effect which i
added to my game, i
wrote a function to BLIT one surface over another using
additive blending,
but it goes pixel by pixel in a double for loop… I was
wondering if theres
any faster way, because lots of lighting lags the hell out of
the engine.
Replies will be much appreciated. heres my code:

void eng::blit_lightmap(SDL_Surface *dest, int dstx, int
dsty, int w, int h,
SDL_Surface
*source, int srcx, int srcy)
{

int ix,iy;
Uint32 pix1,pix2;
for(iy=0;iy<h;iy++)
{
for(ix=0;ix<w;ix++)
{
if(dstx+ix<0||dsty+iy<0)continue;
if(dstx+ix>=dest->w||dsty+iy>=dest->h){continue;}
if(srcx+ix>=source->w||srcy+iy>=source->h){continue;}

pix2=SDL_GetPixel(source,srcx+ix,srcy+iy);
  if(pix2)
  {
    pix1=SDL_GetPixel(dest,dstx+ix,dsty+iy);
    SDL_PutPixel(dest,dstx+ix,dsty+iy,lightencolors(pix1,pix2));
  }

}
}
}


MSN 8: Get 6 months for $9.95/month.
http://join.msn.com/?page=dept/dialup


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