SFML community forums

Help => Graphics => Topic started by: smilesprower on April 10, 2016, 10:51:37 pm

Title: Loking for a better solution for swapping pixel colors
Post by: smilesprower on April 10, 2016, 10:51:37 pm
Basically what I am at, is trying to change certain colors of a sprite to other colors. "Palette Swap kind of"

I can do it by changing the images pixels and tex.update(image), sprite.setTex(tex)
Is there an easier option to do this ?

Would using opengl help and can I still use sprite instead of a quad ?

Thanks in advance.
Title: Re: Loking for a better solution for swapping pixel colors
Post by: eXpl0it3r on April 10, 2016, 10:55:35 pm
Depends on what exactly you want to change. What you can do is call setColor on the sprite.
If only parts should change, you could use a texture just with these parts and then use two sprites for the objects, where for one you can set the color and/or "bake" the different colors onto one render texture. Similar to how AFSis doing it for his game (http://en.sfml-dev.org/forums/index.php?topic=19672.msg144685#msg144685).
Title: Re: Loking for a better solution for swapping pixel colors
Post by: smilesprower on April 11, 2016, 10:31:39 am
Seems like a very good idea, but it means I would have to rip apart every sprite in the sprite sheet.
For example lets say there are 6 pieces that can change colour, this seems a bit much


Do you know of any other examples or people who shared the same problems ?
Title: Re: Loking for a better solution for swapping pixel colors
Post by: Laurent on April 11, 2016, 10:50:31 am
The obvious solution to this problem is to use a fragment shader. You can send your palette to it and apply it according to however you encoded the "areas" in the source texture.
Title: Re: Loking for a better solution for swapping pixel colors
Post by: smilesprower on April 11, 2016, 03:00:29 pm
Would you have a link to a solution or help guide using opengl frag shaders ?
Title: Re: Loking for a better solution for swapping pixel colors
Post by: Mr_Blame on April 11, 2016, 04:42:33 pm
http://www.sfml-dev.org/tutorials/2.3/graphics-shader.php there you can find examples of shaders