Skip to main content

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.

Text labels and rectangles are the simplest LWXGL elements — they display static content and can be repositioned or hidden at runtime. Both are non-interactive by default, though GElemInside can be used to test whether the mouse cursor is hovering over them.

GCreateText

void GCreateText(int id, int x, int y, int color, const char* text)
Creates a text label element at the given position. The text is rendered using a 9×15 pixel font and split into lines on \n characters. Each line is 16 px tall (15 px glyph + 1 px leading).
id
int
required
Element slot index. If the slot is already occupied, the existing element is deleted first.
x
int
required
Left edge of the text in window pixels.
y
int
required
Top edge of the first line in window pixels. The baseline of the first line is drawn at y + 11.
color
int
required
Palette index (0–15) for the text color.
text
const char*
required
Null-terminated string to display. \n characters create additional lines. The pointer is stored directly — do not free or move the string while the element exists.
Because the text pointer is stored by reference, string literals and static buffers are safe. Heap-allocated strings must remain valid for the lifetime of the element.

GCreateRect

void GCreateRect(int id, int x, int y, int w, int h, int fg, int bg)
Creates a filled rectangle with an optional border outline.
id
int
required
Element slot index.
x
int
required
Left edge in window pixels.
y
int
required
Top edge in window pixels.
w
int
required
Width in pixels.
h
int
required
Height in pixels.
fg
int
required
Border color as a palette index (0–15). Pass -1 to draw no border.
bg
int
required
Fill color as a palette index (0–15). Pass -1 for a transparent (no fill) rectangle, leaving the background visible inside the border.
The border is drawn with XDrawRectangle, which insets the right and bottom edges by 1 px, so the effective outer size is w × h and the stroke falls inside that area.

GDeleteElement

void GDeleteElement(int id)
Frees the element occupying slot id and sets the slot to NULL. All internal memory for the element (including any XImage data for image elements) is released.
id
int
required
Element slot index to delete. Safe to call when the slot is already NULL or when id is out of the current element vector range — both cases are silently ignored.

GElemModifyBounds

void GElemModifyBounds(int id, int x, int y, int w, int h)
Updates the position and size of element id at runtime. The change takes effect on the next GRenderWindow call. Works for all element types.
id
int
required
Element slot index.
x
int
required
New left edge in window pixels.
y
int
required
New top edge in window pixels.
w
int
required
New width in pixels. For text elements this value is stored but not used by the renderer; pass 0 if not applicable.
h
int
required
New height in pixels. Same note as w for text elements.
Resizing an image element with GElemModifyBounds changes only the stored bounds — it does not reallocate the underlying XImage. If the new size is larger than the original, pixels outside the original allocation will not be rendered correctly. Recreate the element with GCreateImage to resize it safely.

GElemSetVisible

void GElemSetVisible(int id, int visible)
Shows or hides element id. Hidden elements are skipped entirely during rendering and do not receive mouse-event processing.
id
int
required
Element slot index.
visible
int
required
1 — show the element (default state after creation). 0 — hide the element.

GElemInside

int GElemInside(int id)
Returns 1 if the current mouse cursor position falls within the element’s bounding box, 0 otherwise. The element must also be visible (GElemSetVisible(..., 1)) to return 1. For checkbox elements the bounding box is extended to include the label text: the right edge is widened by 6 + label_char_count * 9 pixels.
id
int
required
Element slot index.
Return value: int1 if the cursor is inside, 0 if not.

Example

// Draw a dark-blue filled rect with a gray border
GCreateRect(0, 10, 10, 200, 40, 7, 1);

// Draw white text label on top
GCreateText(1, 20, 20, 15, "Score: 0");

// Later — move the rect down the screen
GElemModifyBounds(0, 10, 100, 200, 40);

// Hide the label temporarily
GElemSetVisible(1, 0);

// Check if the mouse is hovering over the rect
if (GElemInside(0)) {
    // highlight or tooltip logic here
}

Build docs developers (and LLMs) love