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

Author Topic: Render colored text  (Read 1488 times)

0 Members and 1 Guest are viewing this topic.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Render colored text
« on: September 30, 2015, 04:47:33 am »
I'm implemented a game console, such as used in Doom, Quake, Stalker, Crysis and other 3D shooters.
It's very useful for debugging and works fast enough, but there is a little question about rendering colored texts.
I'm using colored text output to make it more readable.
For simplification purposes, I'm using special text codes to switch current text color. For exampe:
"$1Hello $2world!"
It will be rendered as white "Hello" and blue "world".
To render such texts I'm split it into several parts for each color and then render it with calling Text.GetLocalBounds to measure it's size.

So, the question - is there any better way to render text which consists of sub-strings with different colors?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Render colored text
« Reply #1 on: September 30, 2015, 02:29:28 pm »
Have you looked into existing solutions? E.g. https://github.com/skyrpex/RichText
SFML / OS X developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Render colored text
« Reply #2 on: September 30, 2015, 03:32:38 pm »
There have also been source codes on this forum and maybe the Wiki, you could search a bit.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything