Help getting SDL_ttf to work

Okay. I run my program on Win32 but it does not run; it gives 0KB stdout
and stderr files. I run it on Linux and it does run, but SDL_ttf doesn’t
seem to be working. It’s as if it weren’t there at all.

Here’s the TTF-related code in my program:

/* Engine-related define; FONT will be used instead of TTF_Font */
#define FONT TTF_Font

/* Init SDL_ttf */
if (TTF_Init() == -1)
fatalError(“Cannot load SDL: %s\n”, TTF_GetError());

/* Load game font */
font = TTF_OpenFont(“ponde___.ttf”, 12);

/* (is supposed to) Prints text to a surface */
void printText(IMAGE *surf, int x, int y, const char *text, FONT *font,
COLOR color)
{
SDL_Surface *rendered = TTF_RenderText_Solid(font, text, color);
SDL_Rect rect;
rect.x = x; rect.y = y;
SDL_BlitSurface(rendered, NULL, surf, &rect);
SDL_FreeSurface(rendered);
}

That’s about it… Has anyone had this problem? I’ll try to look deeper
into my code since I’m in ubercoder mode right now. Thanks in advance
for any tips.

You need more error checking.

Check the return values of both TTF_OpenFont() and TTF_RenderText_*().
If either are NULL then use TTF_GetError() to find out why.On 3/25/07, L-28C wrote:

Okay. I run my program on Win32 but it does not run; it gives 0KB stdout
and stderr files. I run it on Linux and it does run, but SDL_ttf doesn’t
seem to be working. It’s as if it weren’t there at all.

Here’s the TTF-related code in my program:

/* Engine-related define; FONT will be used instead of TTF_Font */
#define FONT TTF_Font

/* Init SDL_ttf */
if (TTF_Init() == -1)
fatalError(“Cannot load SDL: %s\n”, TTF_GetError());

/* Load game font */
font = TTF_OpenFont(“ponde___.ttf”, 12);

/* (is supposed to) Prints text to a surface */
void printText(IMAGE *surf, int x, int y, const char *text, FONT *font,
COLOR color)
{
SDL_Surface *rendered = TTF_RenderText_Solid(font, text, color);
SDL_Rect rect;
rect.x = x; rect.y = y;
SDL_BlitSurface(rendered, NULL, surf, &rect);
SDL_FreeSurface(rendered);
}

That’s about it… Has anyone had this problem? I’ll try to look deeper
into my code since I’m in ubercoder mode right now. Thanks in advance
for any tips.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org