Text elements render a string at a fixed position in the window each frame using LWXGL’s bitmap font. Two creation functions are provided:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DRESsedAlarm184/LWXGL/llms.txt
Use this file to discover all available pages before exploring further.
CreateText holds a pointer to your string without copying it, while CreateCopiedText duplicates the string onto the heap so the original can be discarded immediately after creation.
Both variants support multi-line strings — lines are split on \n characters and rendered 15 pixels apart. The active font (9x15 or 9x15bold) applies to all text elements and can be switched globally with SetGlobalBold.
Rendering Details
- Font:
9x15(or9x15boldafterSetGlobalBold(1)). Each character is 9 px wide; lines are 15 px tall. - Rendered via
XDrawStringonto the back-buffer pixmap each frame. - The y coordinate passed to
Create*maps to the top of the first line; the baseline is drawn aty + 11internally (matchingImmediateTextbehavior). - Newline characters (
\n) are supported; every subsequent line steps 15 px down. SetGlobalBold(int bold)— pass1to switch to9x15bold,0to revert. Returns1on success. Affects all text elements rendered from the next frame onward.
Functions
CreateText
Creates a text label element that renderstext every frame. The pointer text is stored as-is — LWXGL does not copy the string. The string must remain valid and unchanged for the entire lifetime of the element.
Unique integer identifier for this element. Used with
DeleteElement, ElemModifyBounds, ElemSetVisible, etc. If an element already exists at this ID it will be overwritten.Horizontal position in pixels from the left edge of the window.
Vertical position in pixels from the top of the window. The rendered baseline sits at
y + 11.Pointer to the null-terminated string to display. Must remain valid until
DeleteElement(id) is called. Supports \n for multi-line output.Text color, one of the
CLR_* palette constants (e.g., CLR_WHITE).CreateText stores the raw pointer. If the string lives on the stack or is freed before DeleteElement is called, rendering that element will produce undefined behaviour. Use CreateCopiedText if you cannot guarantee the pointer’s lifetime.CreateCopiedText
Creates a text label element likeCreateText, but internally calls strdup to copy the string onto the heap. The original pointer can be freed or go out of scope immediately after this call. LWXGL frees the copy when DeleteElement is called.
Unique integer identifier for this element.
Horizontal position in pixels from the left edge of the window.
Vertical position in pixels from the top of the window.
Null-terminated string to display. A heap copy is made immediately; the original may be freed after this call returns.
Text color, one of the
CLR_* palette constants.