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

Author Topic: Multiple Colors in sf::Text  (Read 1109 times)

0 Members and 1 Guest are viewing this topic.


  • Full Member
  • ***
  • Posts: 162
    • View Profile
Multiple Colors in sf::Text
« on: January 06, 2019, 09:26:10 am »
Would it be possible to have sf::Text use multiple colors? As far as implementation goes, it could hold a vector of strings instead of one and you could do something like

txtObject.addString("str", sf::Color::Red)

instead of just setString().


  • SFML Team
  • Hero Member
  • *****
  • Posts: 6208
  • Thor Developer
    • View Profile
    • Bromeon
Re: Multiple Colors in sf::Text
« Reply #1 on: January 06, 2019, 01:44:47 pm »
This would lead to a complex formatting feature -- the next request would be to apply style (bold/italics/underline) and size (pt) partially.

It's possible to build such a formatter out of separate sf::Text instances, and it has been done before, IIRC one of them with a markup language similar to HTML. If you look on the forum or the Wiki, you should find such extensions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: first SFML book


  • SFML Team
  • Hero Member
  • *****
  • Posts: 9508
    • View Profile
    • development blog
    • Email
Re: Multiple Colors in sf::Text
« Reply #2 on: January 06, 2019, 02:41:18 pm »
There are extension libraries like RichText that provide such features: https://github.com/skyrpex/RichText

I'd say it's not necessarily out of SFML's scope, but since it can be implemented in many ways with certain trade-offs, it's not as simple to pick an API that works for most everyone.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/