المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Help with how to add/mix RGBA values



C++ Programming
04-08-2009, 03:32 PM
Hi.

I'm currently working on a game where I do some simple pixel modifications when loading graphics. What I tried to do was to build a function that could take two RGBA values and add them, but I'm having real trouble with the alpha values. I know how to do it when using only RGB colors but when including alpha everything gets much trickier. I would like to have a function like this:


u32 blendPixel(u32 baseColor, u32 paintColor) {
u8 baseRed = getRed(baseColor);
u8 baseGreen = getGreen(baseColor);
u8 baseBlue = getBlue(baseColor);
u8 baseAlpha = getAlpha(baseColor);

u8 paintRed = getRed(paintColor);
u8 paintGreen = getGreen(paintColor);
u8 paintBlue = getBlue(paintColor);
u8 paintAlpha = getAlpha(paintColor);

u8 newRed = ???
u8 newGreen = ???
u8 newBlue = ???
u8 newAlpha = ???

return makecol(newRed, newGreen, newBlue, newAlpha);
}