Category: libraries

How slow is SDL_TTF 2.0?

How slow is SDL_TTF 2.0?

FWhen  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.

 

Single file libraries

Single file libraries

open book lot
Library image from Unsplash.com

Most days I scan the web for relevant or interesting stuff and today I found a real treasure. A website where they have curated a list of C and C++ single file libraries. That is libraries that are not multiple files but mostly one. I say mostly because there are a few with 2 or 3 files.

The bulk are in C++ but there are a large number of C/C++ and quite a number of C. All have their licensing; these are open source but licences vary a bit.

It’s worth a trawl through the List. For instance there’s an interpreter for a BASIC dialect scripting language,