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

Author Topic: sf::Font - Multiple colors  (Read 2449 times)

0 Members and 1 Guest are viewing this topic.

Pheelbert

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
sf::Font - Multiple colors
« on: November 03, 2013, 12:47:07 am »
I just created a .ttf and realized fonts didn't have color ...
(if there is then correct me, but they are all black characters and I can't seem to change that).

So I was wondering if there was an easy way to draw colors onto characters (not only one).

Example:

(As you can see -or not since it's so small- I just want to have two different colors, bluish and pale bluish in the middle)
« Last Edit: November 03, 2013, 12:53:45 am by Pheelbert »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11004
    • View Profile
    • development blog
    • Email
Re: sf::Font - Multiple colors
« Reply #1 on: November 03, 2013, 01:29:41 am »
Since the font is the pure data/information on how the character's shape should look like, it doesn't contain any color information.
You can set a single color on an sf::Text object (see the documentation), but if you want two colors on one text, you'll have to probably some extra work.
A straight forward way would be to render the colors and the text to a render texture with the right blend modes and then extracting the text from there.
A more complex but probably more performant way would be to make your own implementation of for text rendering by basing it off SFML's version and add the multi color drawing - no idea if that would work though.

Or you could think about using an image, but with lots of text this is not really an option.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: sf::Font - Multiple colors
« Reply #2 on: November 03, 2013, 01:49:13 am »
I would think making a colored image containing all characters you need and then using it like a sprite sheet, is far easier than fiddling with creation of suitable font files to enable shoehorning colors in by making 2-part-characters you draw over each other.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11004
    • View Profile
    • development blog
    • Email
Re: sf::Font - Multiple colors
« Reply #3 on: November 03, 2013, 01:55:34 am »
It really depends on the use case, reimplementing your own version of fonts using a bitmap font works too, but it kind of defeats the whole purpose of having SFML... :P
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Pheelbert

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: sf::Font - Multiple colors
« Reply #4 on: November 03, 2013, 02:08:31 am »
Thanks for the responses, I'll try to fiddle something out by like drawing the text three times and <?> do something to hide the parts I don't want to create the illusion that I have two different colors.. Or something.

 

anything