mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-26 13:34:22 +01:00
33 lines
602 B
C++
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;
|
|
}
|