SFML community forums
Help => Graphics => Topic started 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.
-
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).
-
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 ?
-
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.
-
Would you have a link to a solution or help guide using opengl frag shaders ?
-
http://www.sfml-dev.org/tutorials/2.3/graphics-shader.php there you can find examples of shaders