PDA

View Full Version : SDL_ttf accessing fonts on a Mac




mkawick
Nov 2, 2008, 09:59 AM
Calling the following TTF_OpenFont function, after installing the SDL_ttf of course, always fails.

int IsEverythingOK = TTF_Init();
if (IsEverythingOK != -1)
{
font=TTF_OpenFont ("Arial.ttf", 10);// fails here
}

This is a common font and everyone should have it installed. I have also tried the following path:
"library/fonts/Arial.ttf"

Does anyone know why? The error code is "Couldn't open Arial.ttf".

Thanks ahead.



lee1210
Nov 2, 2008, 11:25 AM
It looks like TTF_OpenFont wraps TTF_OpenFontIndex, which wraps TTF_OpenFontRW and SDL_RWFromFile. The lowest level seems to be SDL_RWFromFile:
http://sdl.beuc.net/sdl.wiki/SDL_RWFromFile

It looks like you need to pass a const char * with the filename, and a const char * with options. This seems to just be a wrapper for fopen:
http://www.manpagez.com/man/3/fopen/

I would play with opening the file with fopen first and make sure that's working, then when you've got the arguments right to open the font with that, move up and make sure this still works with SDL_RWFromFile. If so, the rest of the levels don't seem to introduce much, so you should be able to jump back up to TTF_OpenFont.

-Lee