frodo-wii/utils.cpp
simon.kagstrom 1d385c66f0 More fixes
2009-11-19 17:59:43 +00:00

33 lines
602 B
C++

TTF_Font *read_font(const char *path)
{
TTF_Font *out;
SDL_RWops *rw;
Uint8 *data = (Uint8*)malloc(1 * 1024*1024);
FILE *fp = fopen(path, "r");
if (!data) {
fprintf(stderr, "Malloc failed\n");
exit(1);
}
if (!fp) {
fprintf(stderr, "Could not open font\n");
exit(1);
}
fread(data, 1, 1 * 1024 * 1024, fp);
rw = SDL_RWFromMem(data, 1 * 1024 * 1024);
if (!rw)
{
fprintf(stderr, "Could not create RW: %s\n", SDL_GetError());
exit(1);
}
out = TTF_OpenFontRW(rw, 1, 20);
if (!out)
{
fprintf(stderr, "Unable to open font %s\n", path);
exit(1);
}
fclose(fp);
return out;
}