Fonts
Text uses a global font, size and color unless a call overrides them. Load a font file with CC_LoadFont after CC_Init(), then make it the default with CC_InitFont. Slot 0 is always raylib's built-in font, and up to 15 more can be loaded.
Example
static uint16_t title_font; // 0 means "use the global font"
static void load_fonts(void) { // call after CC_Init()
int body = CC_LoadFont("resources/Inter-Regular.ttf", 18);
int title = CC_LoadFont("resources/Inter-Bold.ttf", 32);
if (body >= 0) CC_InitFont(body, 18); // default for every Text
if (title >= 0) title_font = (uint16_t)title; // -1 means the load failed
CC_SetGlobalFontColor(ColorHex(0xECECEC));
}
static void header(void) {
Text("Settings", .fontId = title_font, .fontSize = 32);
Text("Uses the global font, size and color");
}
Reference
| Name | Signature | What it does | Page |
|---|---|---|---|
CC_LoadFont | int (const char *path, int base_size) | Load a font file into a new slot (up to 15). Returns its id, or -1 on failure. Call after CC_Init. | Lifecycle |
CC_InitFont | int (int fontId, int base_size) | Make a loaded font the global default for Text, and optionally set the default size. | Lifecycle |
CC_GetGlobalFontId | int (void) | Current default font id. | Lifecycle |
CC_GetGlobalFontSize | int (void) | Current default font size. Starts at CC_DEFAULT_FONT_SIZE. | Lifecycle |
CC_SetGlobalFontColor | int (CC_Color color) | Default text color for Text, dividers and progress indicators. | Lifecycle |
CC_GetGlobalFontColor | CC_Color (void) | Current default text color. | Lifecycle |