From e18c4c1158752ae29726eb164006d22de24a6c7e Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 20 Jun 2020 23:32:32 +0200 Subject: [PATCH] REVIEWED: ColorAlphaBlend(), support tint color --- src/textures.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/textures.c b/src/textures.c index ee3f0ab4b..8f93383e3 100644 --- a/src/textures.c +++ b/src/textures.c @@ -3388,18 +3388,15 @@ Color ColorAlphaBlend(Color dst, Color src, Color tint) { Color out = WHITE; - // TODO: Compute tint color over source properly (before alpha blending) - + // Apply color tint to source color + src.r = (unsigned char)(((unsigned int)src.r*(unsigned int)tint.r) >> 8); + src.g = (unsigned char)(((unsigned int)src.g*(unsigned int)tint.g) >> 8); + src.b = (unsigned char)(((unsigned int)src.b*(unsigned int)tint.b) >> 8); + src.a = (unsigned char)(((unsigned int)src.a*(unsigned int)tint.a) >> 8); + //#define COLORALPHABLEND_FLOAT #define COLORALPHABLEND_INTEGERS #if defined(COLORALPHABLEND_INTEGERS) - // Apply color tint to source color - // NOTE: Some problems when aplying source tinting - //src.r = (unsigned char)(((unsigned int)src.r*(unsigned int)tint.r) >> 8); - //src.g = (unsigned char)(((unsigned int)src.g*(unsigned int)tint.g) >> 8); - //src.b = (unsigned char)(((unsigned int)src.b*(unsigned int)tint.b) >> 8); - //src.a = (unsigned char)(((unsigned int)src.a*255 + (unsigned int)tint.a*(255 - src.a)) >> 8); - if (src.a == 0) out = dst; else if (src.a == 255) out = src; else @@ -3416,9 +3413,6 @@ Color ColorAlphaBlend(Color dst, Color src, Color tint) } #endif #if defined(COLORALPHABLEND_FLOAT) - // Apply color tint to source color - //fsrc.x *= ftint.x; fsrc.y *= ftint.y; fsrc.z *= ftint.z; fsrc.w *= ftint.w; - if (src.a == 0) out = dst; else if (src.a == 255) out = src; else