Best font rendering


quadcricket

Very Active Member
Joined
Mar 28, 2008
Messages
104
I'm beginning to learn C/SDL to try creating homebrew for the Pandora.


What is a good way to render text to a surface that will work well on the Pandora?


(I don't have my Pandora yet.)


It doesn't have to be dynamic or 3D. I just want a portable way to render anti-aliased fonts.


Thanks in advance
 
http://www.libsdl.org/projects/SDL_ttf/ should be fine for you. I use it for my projects, too.


If you change the text to display quite often (e.g. every frame), it could be a good idea to precalculate surfaces for e.g. every ASCII letter and then blit the words on your own :)


Edit: Oh, most important: SDL_tff is on every open handheld (including the pandora) preinstalled. :D
 
Last edited by a moderator:
http://www.libsdl.or...ojects/SDL_ttf/ should be fine for you. I use it for my projects, too.


If you change the text to display quite often (e.g. every frame), it could be a good idea to precalculate surfaces for e.g. every ASCII letter and then blit the words on your own :)


Edit: Oh, most important: SDL_tff is on every open handheld (including the pandora) preinstalled. :D

Very good to know! I had been seeing tutorials recommending SDL_ttf but was worried that it wasn't included on open handhelds and I would have to include it or static compile or something.


I'm not sure what you mean by precalculate for every ASCII letter and then blit though. Do you mean just render the text to a separate surface and then write that surface to the primary one?


Thanks Ziz!
 
SDL_ttf blits any given text to SDL surfaces. But depending on the quality (with or without anti aliasing) this can take a while. So instead of recreating the surface every frame plus blitting it (and blitting with a "real" alpha channel takes some time, too) it is smarter to create 224 Surfaces for every ASCII-sign (starting with ' ' (space)) and draw the text on your own like this (with given position (START_X,y) and text in "str"):



Code:
int x = START_X;

for (int i = 0; str[i] != 0; i++) {

  fancy_blit_function(x,y,letter[str[i]-' '])

  x += letter[str[i]-' ']->w;

}
 
Ah, ok. Very cool.


I'm trying to get a full demo of that working now.


Thanks again
 
Back
Top