But if you're going to do this often, I suggest you do some operator overloading.
Title: Re: sf::Color multiplication not working
Post by: Laurent on July 27, 2020, 08:23:23 am
Quote
Just multiply each element individually like so:
Not like so. You must then divide by 255 to bring it back to range [0 .. 255]. Or normalize components in [0 .. 1], if you need to do a lot of these multiplications.
Title: Re: sf::Color multiplication not working
Post by: pm123 on July 27, 2020, 01:13:57 pm
Yes, thats what I ended up doing. But the docs say it should work. Also had to watch out for subtracting the transparency value.
Title: Re: sf::Color multiplication not working
Post by: Laurent on July 27, 2020, 03:23:37 pm
Indeed, if this operator is already defined in SFML, it should work as expected. And it looks like it does, what do you think is wrong in your example?
Title: Re: sf::Color multiplication not working
Post by: pm123 on July 27, 2020, 04:32:44 pm
dec1: 0 0 1 icolor: 80 80 80 mult: 0 0 0
mult=dec1*icolor produces zeroes instead of 0,0,80
Title: Re: sf::Color multiplication not working
Post by: Laurent on July 27, 2020, 05:16:21 pm
(1 * 80) / 255 = 0, not 80.
You should get more familiar with how color multiplication works ;)
Title: Re: sf::Color multiplication not working
Post by: pm123 on July 27, 2020, 07:05:21 pm
Ah ok, I though taking modulo 256 would make something range 0->255 but I guess that's not the standard. So when multiplying I actually want my decr to be 255 and not 1.
Title: Re: sf::Color multiplication not working
Post by: Laurent on July 27, 2020, 08:29:26 pm
So, multiply by 255.
To make color multiplication more intuitive, normalize the components: convert them from [0 .. 255] to [0 .. 1] (ie. divide by 255). Then you can multiply using standard maths conventions.