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

Author Topic: getting the best performance when animating text strings  (Read 3089 times)

0 Members and 1 Guest are viewing this topic.

bobl

  • Newbie
  • *
  • Posts: 18
    • View Profile
getting the best performance when animating text strings
« on: February 15, 2010, 04:19:06 pm »
I'm currently animating text strings by repeating these lines ie...
Code: [Select]

       App.Clear();
       Text.SetText(  Some_function_that_returns_a_string()  );
       App.Draw(Text);
       App.Display();

once for each frame ie by placing them inside a loop.
My full example is here...
Code: [Select]

http://www.sfml-dev.org/forum/viewtopic.php?t=2189&highlight=


Ultimately many strings will be displayed on screen but most won't change from frame to frame.  
The way I'm doing it now, I think I have to Text.SetText() every string that gets displayed
ie even those strings that don't change between frames
which seems wasteful.

Additionally, I was recently advised that...
Code: [Select]

The number one mistake people make in doing text apps in OpenGL is
they do not cache individual character glyphs as textures.
They either reconvert from the font (very slow) each time they draw a character
or
they upload the glyphs (slow) each time they draw the character.
If you create each glyph as a texture with only the alpha plane
you can scale the characters to any size you need and paint them any way you want
and since modern graphics cards are designed to render textures you get the best speed possible.


How can I speed up my program to take account of the above advice and that most strings will not change between frames.

Thank you in anticipation.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
getting the best performance when animating text strings
« Reply #1 on: February 15, 2010, 04:49:13 pm »
You can't, because:
1- Text.SetText doesn't do anything else than storing the string that you pass, so it's not really wasteful
2- SFML already uses the technique you describe, glyphs are cached in textures and simply reused when rendering text

If your application is slow then we can investigate other ways to improve speed, but nothing related to text rendering.
Laurent Gomila - SFML developer

bobl

  • Newbie
  • *
  • Posts: 18
    • View Profile
getting the best performance when animating text strings
« Reply #2 on: February 15, 2010, 06:45:56 pm »
I'm really pleased to hear that this sort of caching is built-in.
That's great!

My program is very fast but I've only got one string in it at present.

I've been trying to formulate a question about the use of textures re the above but am struggling. I need to develop the above example further, to make the question clear and will come back when I've done this.

In the meantime...thank you very much for your help.

 

anything