craigix
Mega GP Mania
Does anyone know if it is possible to include a font with an SDL program? And if so how it is done?
Thanks,
Craig
Thanks,
Craig
Mr.Jabberwocky posted on Oct 13 2006 at 08:39 AM said:I thought he meant he wants to include the font in the binary instead of loading it.
If you want to have a font bitmap compiled into your code and used from there, you can do it using SFont (as criticalbeeb does) but use IMG_Load_RW to get the font bitmap from memory, rather than getting it from a file.craigix posted on Oct 13 2006 at 03:00 AM said:Does anyone know if it is possible to include a font with an SDL program? And if so how it is done?
woogal posted on Oct 13 2006 at 09:42 AM said:You use rwops to load any data thats included, but I'm sure I read somewhere once that ttf fonts don't work too well in this way. If you want to use ttf instead of bitmap fonts then you could always try including the font, write the data out to /tmp when the app loads, then use the normal ttf functions to load it back in again.
craigix posted on Oct 13 2006 at 10:42 AM said:woogal posted on Oct 13 2006 at 09:42 AM said:You use rwops to load any data thats included, but I'm sure I read somewhere once that ttf fonts don't work too well in this way. If you want to use ttf instead of bitmap fonts then you could always try including the font, write the data out to /tmp when the app loads, then use the normal ttf functions to load it back in again.
That does seem the only way to do it, bit crazy isn't it?
TTF_Font *TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize)
src
The source SDL_RWops as a pointer. The font is loaded from this.
freesrc
A non-zero value mean is will automatically close/free the src for you.
ptsize
Point size (based on 72DPI) to load font as. This basically translates to pixel height.
Load src for use as a font, at ptsize size. This is actually TTF_OpenFontIndexRW(src, freesrc, ptsize, 0) This can load TTF and FON formats. Using SDL_RWops is not covered here, but they enable you to load from almost any source. NOTE: src is not checked for NULL, so be careful.
// load font.ttf at size 16 into font
TTF_Font *font;
sample=TTF_OpenFontRW(SDL_RWFromFile("font.ttf"), 1, 16);
if(!sample) {
printf("TTF_OpenFontRW: %s\n", TTF_GetError());
// handle error
}
/*
Note that this is unsafe because we don't check the validity of the SDL_RWFromFile's returned pointer.
*/
GnoStiC posted on Oct 14 2006 at 09:33 AM said:TTF_Font *TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize)
src
The source SDL_RWops as a pointer. The font is loaded from this.
freesrc
A non-zero value mean is will automatically close/free the src for you.
ptsize
Point size (based on 72DPI) to load font as. This basically translates to pixel height.
Load src for use as a font, at ptsize size. This is actually TTF_OpenFontIndexRW(src, freesrc, ptsize, 0) This can load TTF and FON formats. Using SDL_RWops is not covered here, but they enable you to load from almost any source. NOTE: src is not checked for NULL, so be careful.
Code:// load font.ttf at size 16 into font TTF_Font *font; sample=TTF_OpenFontRW(SDL_RWFromFile("font.ttf"), 1, 16); if(!sample) { printf("TTF_OpenFontRW: %s\n", TTF_GetError()); // handle error } /* Note that this is unsafe because we don't check the validity of the SDL_RWFromFile's returned pointer. */
i haven't tried this, but i remember gp2x_future_coder having problem while back at http://www.gp32x.de/board/index.php?showtopic=29719
can somebody else verify it? (i don't have my gp2x here (at work))..