[SDL] What is wrong with SDL_TTF?

Ricardo Cruz rpmcruz at clix.pt
Mon Sep 12 10:21:56 PDT 2005

Em Segunda, 12 de Setembro de 2005 15:46, o kds71 escreveu:
> Hello everybody!
> I'm trying to use SDL_TTF to render a lot of text. But it's extremally
> slow. On Sempron 2500+ 256 mb ram GeForce 4 it is running great. On
> Duron 800 128 mb ram Riva 2 I have about 50 fps - it's acceptable. But
> on Pentium III 450 mhz 320 mb ram I have for 10 to 25 fps.
> 1) Why it's so slow?

 TTF is a vectorial graphics format, so a bitmap representation must be 
created on the fly. This consumes CPU. Though it does some caching, there is 
always some CPU impact.

> 2) It's possible to render more than one line of text on one surface?

 If the render function of SDL_TTF doesn't support breaklines, you could 
easily add a wrapper function to support that, as well as allignment.
 You'll probably need a wrapper function to add some appealing visual effect, 
like gradient, to the fonts anyway.

> 3) Is there any portable alternative way to render text with SDL?
 Yes, bitmaps fonts. Some dude just announced a SDL tutorial that has a 
section dedicated to that:

 SuperTux also uses bitmap fonts (check latest stable version, svn is just too 
confusing right now):

 The cons about bitmap font is that if you want different size you have to do 
them before (scaling won't look nice) and there aren't as many available as 
TTF, so you might need to draw them yourself. The pros is that it's faster 
and looks prettier (well, depends on the artist ;)).

 If you want to be able to draw the font in a lot of different colors, just 
make a monochrom bitmap and then, on the loading function, replace the black 
(or whatever) pixel by the passed color.

 You can also use something like the SDL_gfx's gfxPrimitivesSetFont(). It uses 
a vectorial representation of its own that draw lines and stuff for the 
different characters. It will look a lot "pixeled" though, but it works nice 
in some games, like in a space invaders clone.


> Thanks a lot.

The more we disagree, the more chance there is that at least one of us is 

More information about the SDL mailing list