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

Author Topic: Is Drawing Text slow?  (Read 3156 times)

0 Members and 1 Guest are viewing this topic.

Megatron

  • Newbie
  • *
  • Posts: 22
    • View Profile
Is Drawing Text slow?
« on: June 11, 2011, 10:28:56 am »
I was curious if sf::Text is known for being slow to draw? This is with regards to SFML 2.0. I'm not sure which revision but it was downloaded/compiled within the last few weeks.

I was working on the user interface for my game, and most of my text is composed of a class called OutlineText.

OutlineText contains 5 sf::Text objects. A quick view of the class with non relevant functions removed is as follows:

Code: [Select]
class OutlinedText
{
public:
        void Draw(sf::RenderWindow &window)
{
window.Draw(BackgroundText);
window.Draw(BackgroundTextXNeg);
window.Draw(BackgroundTextY);
window.Draw(BackgroundTextYNeg);
                window.Draw(BaseText);
        }
protected:
std::string text;
sf::Text BaseText;
sf::Text BackgroundText;
sf::Text BackgroundTextXNeg;
sf::Text BackgroundTextY;
sf::Text BackgroundTextYNeg;
}


I make heavy use of this class to produce an outlined effect around my central text. (I.E. BaseText would be white and the other 4 would be black to give it the appearance of being outlined in black) If someone has a better suggestion on how to do this, that'd be great, but for now this does work.

I added a few instances (36 OutlinedText so 180 sf::Text instances) of this class and i saw a pretty noticeable increase in CPU usage versus when I was drawing tile maps/some other images(the number of tiles plus other images that are rendered can easily more then 200) For instance at 800x600x32, 150fps it went from 2-3% CPU usage with the tilemap/others in debug to 7-8+% CPU usage in debug and from ~0% CPU usage in release to 1-2+% CPU usage in release - not a huge concern right now, but the interface isn't done so usage is only going to go up. Profiling my code did show rendering Text to be the hot path. So I was curious if I'm supposed to be seeing this increase? Or perhaps something is off about my setup.

If it makes a difference, the text is colored a variety of colors (all at default alphas) and I'm using 3 different fonts amongst the various OutlinedText instances. This is compiled in Visual Studio 2010 under windows 7 x64, and release mode is set to Full Optimization.

For Clairty, Here's an example screenshot showing the Outlined Text. Note that if I draw everything except the text below the character portraits (i.e. the tilemap, picture stack to the right, character portraits etc. the cpu usage is at the low levels I stated above. Pardon the messiness, Those graphics are there to show my point)
http://garyoak.com/samples/Screenshot1.png

And the First page of the code profile showing the render text is the hot path (plus what it break down to)
http://garyoak.com/samples/Sampling.png

Thanks in advance

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is Drawing Text slow?
« Reply #1 on: June 11, 2011, 10:39:33 am »
I don't think there's anything wrong in using 1% CPU to draw 180 sf::Text. Everything's perfectly normal.
Laurent Gomila - SFML developer

Megatron

  • Newbie
  • *
  • Posts: 22
    • View Profile
Is Drawing Text slow?
« Reply #2 on: June 11, 2011, 07:19:44 pm »
Ah alright. I guess I was expecting drawing text to be as/nearly as fast as drawing sprites

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is Drawing Text slow?
« Reply #3 on: June 11, 2011, 07:41:36 pm »
Drawing a single character is as fast as drawing a sprite. So drawing a complete string is of course slower ;)
Laurent Gomila - SFML developer