Skip to main content

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​

NameSignatureWhat it doesPage
CC_LoadFontint (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_InitFontint (int fontId, int base_size)Make a loaded font the global default for Text, and optionally set the default size.Lifecycle
CC_GetGlobalFontIdint (void)Current default font id.Lifecycle
CC_GetGlobalFontSizeint (void)Current default font size. Starts at CC_DEFAULT_FONT_SIZE.Lifecycle
CC_SetGlobalFontColorint (CC_Color color)Default text color for Text, dividers and progress indicators.Lifecycle
CC_GetGlobalFontColorCC_Color (void)Current default text color.Lifecycle