SDL_ttf accessing fonts on a Mac

Discussion in 'Mac Programming' started by mkawick, Nov 2, 2008.

  1. mkawick macrumors newbie

    Joined:
    Oct 21, 2008
    Location:
    Vancouver, BC
    #1
    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.
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     

Share This Page