Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Loking for a better solution for swapping pixel colors  (Read 2863 times)

0 Members and 1 Guest are viewing this topic.

smilesprower

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Loking for a better solution for swapping pixel colors
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Loking for a better solution for swapping pixel colors
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

smilesprower

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: Loking for a better solution for swapping pixel colors
« Reply #2 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Loking for a better solution for swapping pixel colors
« Reply #3 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.
Laurent Gomila - SFML developer

smilesprower

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: Loking for a better solution for swapping pixel colors
« Reply #4 on: April 11, 2016, 03:00:29 pm »
Would you have a link to a solution or help guide using opengl frag shaders ?

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Loking for a better solution for swapping pixel colors
« Reply #5 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

 

anything