Add LoadTTFFromFile

This commit is contained in:
Harrison 2022-02-26 09:30:36 -05:00 committed by Crayon
parent c4321117e8
commit 72eae433e6
2 changed files with 31 additions and 4 deletions

View file

@ -81,7 +81,7 @@ GRRLIB_texImg* GRRLIB_LoadTextureFromFile(const char *filename) {
GRRLIB_texImg *tex;
u8 *data;
// return NULL it load fails
// Return NULL if load fails
if (GRRLIB_LoadFile(filename, &data) <= 0) {
return NULL;
}
@ -95,6 +95,32 @@ GRRLIB_texImg* GRRLIB_LoadTextureFromFile(const char *filename) {
return tex;
}
/**
* Load a TTF from a file.
* @param filename The TTF filename to load.
* @return A GRRLIB_ttfFont structure filled with font information.
* If an error occurs NULL will be returned.
*/
GRRLIB_ttfFont* GRRLIB_LoadTTFFromFile(const char *filename) {
GRRLIB_ttfFont *ttf;
u8 *data;
s32 size = GRRLIB_LoadFile(filename, &data);
// Return NULL if load fails
if (size <= 0) {
return NULL;
}
// Convert to TTF
ttf = GRRLIB_LoadTTF(data, size);
// Free up the buffer
free(data);
return ttf;
}
/**
* Make a PNG screenshot.
* It should be called after drawing stuff on the screen, but before GRRLIB_Render.

View file

@ -88,9 +88,10 @@ void GRRLIB_Circle (const f32 x, const f32 y, const f32 radius,
//------------------------------------------------------------------------------
// GRRLIB_fileIO - File I/O (SD Card)
int GRRLIB_LoadFile (const char* filename, u8* *data);
GRRLIB_texImg* GRRLIB_LoadTextureFromFile (const char* filename);
bool GRRLIB_ScrShot (const char* filename);
int GRRLIB_LoadFile (const char* filename, u8* *data);
GRRLIB_texImg* GRRLIB_LoadTextureFromFile (const char* filename);
GRRLIB_ttfFont* GRRLIB_LoadTTFFromFile (const char* filename);
bool GRRLIB_ScrShot (const char* filename);
//------------------------------------------------------------------------------
// GRRLIB_print.c - Will someone please tell me what these are :)