Blending/combinding/merging colors with SDL

Does anyone know how to combine/merge colors with SDL?

I am using the SDL_MapRGB() function.

I want to like combine two colors
For example

gray=mergeColor(black,white,0.5);

any ideas?

Simple multiplication should do it. Assuming the third parameter
specifies how much you want of the first parameter, the expression you
need is:

mergeChannel(a, b, amount):
float result = (a * amount) + (b * (1 - amount))
return int(result)

mergeColour(a, b, amount):
colour result
result.r = mergeChannel(a.r, b.r, amount)
result.g = mergeChannel(a.g, b.g, amount)
result.b = mergeChannel(a.b, b.b, amount)
result.a = mergeChannel(a.a, b.a, amount)
return result

Something like that. The exact formula depends on how you want the
third parameter to behave. You might just want X% of both colours, but
this does X% of colour 1 and (100 - X)% of colour two.On 17 February 2011 15:12, theweirdn8 wrote:

Does anyone know how to combine/merge colors with SDL?

thank you. This actually works.

I had to do a little modifications, but this is now epic!

For my game, what do you want to have for you in the creditS?

Credits for explaining what a “lerp” is?On Sun, Feb 27, 2011 at 4:14 PM, theweirdn8 wrote:

thank you. This actually works.

I had to do a little modifications, but this is now epic!

For my game, what do you want to have for you in the creditS?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

There is no need for credits. Just enjoy =] You could credit the SDL
mailing list if you like.

– BrianOn 27 February 2011 22:14, theweirdn8 wrote:

thank you. This actually works.

I had to do a little modifications, but this is now epic!

For my game, what do you want to have for you in the creditS?

Linear interpolation:

Or did you mean the other kind of lerp :wink:

JeffOn Sunday 27 February 2011 14:53, Patrick Baggett wrote:

Credits for explaining what a “lerp” is?