How slow is SDL_TTF 2.0?
When I created the Asteroids game, I deliberately didn’t use SDL_TTF instead I took a Monospaced font and saved it out as a PNG file which was loaded into a SDL Texture. I then created my own character printing routines by figuring out which character I wanted and then blitting it. The image shows the font I used zoomed in.
You probably can’t get much faster than that, although I wasn’t really doing that much output. Every frame, the score is output and if an asteroid is hit, the value of the hit scrolls upward for a few frames.
Also when you lost a life, it would print using a scaled up version of the font. The only problem with that is scaling up a bit map font just shows off the deficiencies of the font scaling as a bitmap, as the image shows. Not exactly smooth is it?
So I’ve decided to write a small program that uses SDL_TTF 2.0 and does high resolution timing to determine exactly how long it takes to draw text using a TTF font. The big advantage of doing that in a game is you can draw different sizes, weight (bold etc) and colour compared to a bitmap font.
But TTF is an interesting format, there’s a lot going on. Letters are drawn using mathematical equations so it is bound to be a bit slower than pure blitting and I’m interested in knowing just how long it takes. It’s all relative, if you view a page of text in MS Word (or just in Windows generally), Windows renders it pretty fast. But its still important to know just how fast. For what I used text for in Asteroids, it probably could have used TTF text but in another game with more text it might be too slow for 60 frames per second.
If it was too slow then perhaps a hybrid approach might work. Figure out what text you’ll need, prerender it into bitmaps (when the program starts up) then use those bitmaps.
So I’ll publish the speed test program once written. Watch this space.