I looked through showfont.c that comes the the ttf library and think I
am doing everything correctly, but nothing displays for me. Can someone
point out what I am doing wrong?
#include “SDL.h”
#include “SDL_ttf.h”
int main(int argc, char** argv){
SDL_Surface *text, *screen;
SDL_Color red;
SDL_Color *pCol;
SDL_Rect dst;
char string[40];
TTF_Font *font;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0){
fprintf(stderr, “Error Initializing SDL: %s\n”, SDL_GetError());
exit(-1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_HWSURFACE);
if(screen == NULL){
fprintf(stderr, “Couldn’t get main screen: %s\n”, SDL_GetError());
exit(-1);
}
if(TTF_Init() < 0){
fprintf(stderr, “Couldn’t initialize TTF Library: %s\n”, SDL_GetError());
exit(-1);
}
atexit(TTF_Quit);
font = TTF_OpenFont(“Inkburro.ttf”, 12);
if(font == NULL){
fprintf(stderr, “Couldn’t open font: %s\n”, SDL_GetError());
}
red.r = 0xFF;
red.g = 0x00;
red.b = 0x00;
pCol = &red;
dst.x = 93;
dst.y = 20;
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
strcpy(string, “Test for SDL_ttf!”);
text = TTF_RenderText_Solid(font, string, *pCol);
if(text != NULL){
SDL_BlitSurface(screen, NULL, text, &dst);
}
else{
fprintf(stderr, “Error rendering text: %s\n”, SDL_GetError());
}
SDL_Flip(screen);
SDL_Delay(2000);
}