Game Development Community

Alpha Blending GBitmaps

by DavidRM · in Torque Game Engine · 07/17/2002 (11:02 am) · 2 replies

I've dug through the source, but I'm not finding a function or method that will simply alpha blend 2 GBitmaps. So, I created my own...but, in the interest of getting something workable ASAP, I went with the simplest possible approach:

void GBitmap::alphaBlend(const GBitmap& rBlend)
{
   for (U32 yy=0; (yy<height) && (yy<rBlend.height); yy++)
   {
      for (U32 xx=0; (xx<width) && (xx<rBlend.width); xx++)
      {
         ColorI sColor, dColor;
         rBlend.getColor(xx,yy,sColor);

         if (sColor.alpha==255)
            setColor(xx,yy,sColor);
         else if (sColor.alpha>0)
         {
            getColor(xx,yy,dColor);
            dColor.red=((sColor.alpha*(sColor.red-dColor.red))/255)+dColor.red;
            dColor.green=((sColor.alpha*(sColor.green-dColor.green))/255)+dColor.green;
            dColor.blue=((sColor.alpha*(sColor.blue-dColor.blue))/255)+dColor.blue;
            setColor(xx,yy,dColor);
         }
      }
   }
}

My question is this: Is there a routine for this already in the source code somewhere that I just didn't see? Or, if not, has someone else created a better (optimized?) function for this that they'd be willing to share?

Thanks.

-David
Samu Games

#1
11/05/2002 (12:31 pm)
a nested for loop and multiplication and division operations.... hmm there's got to be a better way to do this bro.
#2
11/05/2002 (12:36 pm)
I'm not arguing...