SFML community forums

Help => Graphics => Topic started by: nimn on December 27, 2017, 08:31:52 am

Title: .setColor and vertex arrays?
Post by: nimn on December 27, 2017, 08:31:52 am
hello,

quick question on vertex arrays and transforms.
I see in sprites there is a set color function allowing tinting as well as opacity changes
However, I do not see it, or how it would be implemented with vertex arrays

I've been all over the tutorials, docs and google - any help?
Title: Re: .setColor and vertex arrays?
Post by: Laurent on December 27, 2017, 09:20:52 am
A vertex array is an array of sf::Vertex. And sf::Vertex has a "color" member. So all you have to do is to iterate and change it.

And don't hesitate to have a look at the implementation (https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/Sprite.cpp#L88), it's simple to read and often gives you the solution without having to read the doc or to ask on the forum.
Title: Re: .setColor and vertex arrays?
Post by: nimn on January 03, 2018, 12:45:20 pm
got it working - thanks for the help!
Title: Re: .setColor and vertex arrays?
Post by: nimn on January 03, 2018, 01:13:00 pm
ok sorry - follow up question...

So the tinting works pretty well in manipulating colors, however, I can't get white with a tint as far as I see.
Is white possible with a colored (non-white) texture? any tricks?

thanks again
Title: Re: .setColor and vertex arrays?
Post by: Laurent on January 03, 2018, 02:19:10 pm
No. Vertex color and texture color are multiplied to produce the final pixel; and the only way to get white is to multiply white and white together.

You'll have to find a more complicated solution (most likely involving blending modes or shaders).