Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
fs_font.h File Reference

Detailed Description

Design Philosophy

These functions load and free font assets which are compiled into the filesystem into RAM. Once loaded into RAM, fonts may be used to draw text to the screen.

For more information about using fonts, see font.h.

For information on asset processing, see assets_preprocessor.

Usage

Load fonts from the filesystem to RAM using loadFont(). Fonts may be loaded to normal RAM, which is smaller and faster, or SPI RAM, which is larger and slower.

Free when done using freeFont(). If a font is not freed, the memory will leak.

Example

// Declare and load a font
font_t ibm;
loadFont("ibm_vga8.font", &ibm, false);
// Draw some white text
drawText(&ibm, c555, "Hello World", 0, 0);
// Free the font
freeFont(&ibm);
int16_t drawText(const font_t *font, paletteColor_t color, const char *text, int16_t xOff, int16_t yOff)
Draw text to a display with the given color and font.
Definition font.c:214
A font is a collection of font_ch_t for all ASCII characters. Each character has the same height and ...
Definition font.h:66
void freeFont(font_t *font)
Free the memory allocated for a font.
Definition fs_font.c:89
bool loadFont(const char *name, font_t *font, bool spiRam)
Load a font from ROM to RAM. Fonts are bitmapped image files that have a single height,...
Definition fs_font.c:32
@ c555
r = 5, g = 5, b = 5
Definition palette.h:239

Go to the source code of this file.

Functions

bool loadFont (const char *name, font_t *font, bool spiRam)
 Load a font from ROM to RAM. Fonts are bitmapped image files that have a single height, all ASCII characters, and a width for each character. PNGs placed in the assets folder before compilation will be automatically flashed to ROM.
 
void freeFont (font_t *font)
 Free the memory allocated for a font.
 

Function Documentation

◆ loadFont()

bool loadFont ( const char * name,
font_t * font,
bool spiRam )

Load a font from ROM to RAM. Fonts are bitmapped image files that have a single height, all ASCII characters, and a width for each character. PNGs placed in the assets folder before compilation will be automatically flashed to ROM.

Parameters
nameThe name of the font to load. The font_t is not allocated by this function
fontA handle to load the font to
spiRamtrue to load to SPI RAM, false to load to normal RAM. SPI RAM is more plentiful but slower to access than normal RAM
Returns
true if the font was loaded successfully false if the font failed to load and should not be used

◆ freeFont()

void freeFont ( font_t * font)

Free the memory allocated for a font.

Parameters
fontThe font handle to free memory from