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.

Rectangle and ellipse elements are the simplest persistent drawing primitives in LWXGL. Each is defined by a bounding box and a pair of colors: fg controls the border (outline) and bg controls the fill. Setting either to CLR_NONE (-1) skips that draw operation entirely, allowing filled shapes without borders, outlined shapes without fills, or both. Both types can be repositioned and resized at any time using ElemModifyBounds.

Color Semantics

ParameterRoleRenders via
fgBorder / outlineXDrawRectangle / XDrawArc
bgFillXFillRectangle / XFillArc
Pass CLR_NONE (-1) for either parameter to suppress that draw call. Both CLR_NONE is legal but produces an invisible element.

Functions

CreateRect

Creates a persistent rectangle element. On each frame, LWXGL first fills the interior (if bg is not CLR_NONE) and then draws the one-pixel border (if fg is not CLR_NONE).
void CreateRect(int id, int x, int y, int w, int h, int fg, int bg);
id
int
required
Unique integer identifier for this element.
x
int
required
Left edge of the rectangle in pixels.
y
int
required
Top edge of the rectangle in pixels.
w
int
required
Width of the rectangle in pixels.
h
int
required
Height of the rectangle in pixels.
fg
int
required
Border color, one of the CLR_* constants. Pass CLR_NONE for no border.
bg
int
required
Fill color, one of the CLR_* constants. Pass CLR_NONE for no fill (transparent).
Known rendering bug in CreateRect: The internal renderer passes e->y (the element’s top-edge position) as the height argument to ImmediateRect instead of e->h. The call in renderer.cc is:
ImmediateRect(e->x, e->y, e->w, e->y, rect->fg, rect->bg);
//                                ^^^^ bug: should be e->h
This means the rendered rectangle’s height equals its Y position, not the height you passed to CreateRect. The h parameter you provide has no effect on the rendered output.As a workaround, draw rectangles directly from your on_every callback using ImmediateRect, which does not have this bug:
// Instead of CreateRect, call this from on_every:
ImmediateRect(x, y, w, h, fg, bg);
CreateEllipse is not affected by this bug — its renderer correctly forwards all four bounding-box values.

CreateEllipse

Creates a persistent ellipse (or circle) element inscribed within the given bounding box. The full 360° arc is drawn using XFillArc and XDrawArc.
void CreateEllipse(int id, int x, int y, int w, int h, int fg, int bg);
id
int
required
Unique integer identifier for this element.
x
int
required
Left edge of the bounding box in pixels.
y
int
required
Top edge of the bounding box in pixels.
w
int
required
Width of the bounding box in pixels. Set equal to h for a perfect circle.
h
int
required
Height of the bounding box in pixels.
fg
int
required
Outline color, one of the CLR_* constants. Pass CLR_NONE for no outline.
bg
int
required
Fill color, one of the CLR_* constants. Pass CLR_NONE for no fill.

ElemModifyBounds

Repositions or resizes any element, including rectangles and ellipses. Pass -1 for w or h to leave the corresponding dimension unchanged.
void ElemModifyBounds(int id, int x, int y, int w, int h);
id
int
required
The identifier of the element to modify.
x
int
required
New x position (left edge).
y
int
required
New y position (top edge).
w
int
required
New width, or -1 to keep the current width.
h
int
required
New height, or -1 to keep the current height.

Code Examples

#include "libLWXGL.h"

static void on_frame(int tick, float dt) { (void)tick; (void)dt; }

int main(void) {
    CreateWindow(500, 300, "Shapes Demo", CLR_BLACK, FLAG_NONE);

    /*
     * NOTE: CreateRect has a known height-rendering bug (see Warning above).
     * The 'h' parameter has no effect; rendered height equals the y position.
     * Use ImmediateRect in on_every for correct rectangle rendering.
     */

    /* 1. Bordered rectangle: white fill, gray border */
    CreateRect(1, 20, 20, 160, 80, CLR_GRAY, CLR_WHITE);

    /* 2. Filled rectangle with no border (solid panel) */
    CreateRect(2, 200, 20, 160, 80, CLR_NONE, CLR_BLUE);

    /* 3. Outline-only rectangle (transparent interior) */
    CreateRect(3, 380, 20, 100, 80, CLR_YELLOW, CLR_NONE);

    /* 4. Ellipse (wide oval): cyan fill, white outline */
    CreateEllipse(4, 20, 130, 200, 80, CLR_WHITE, CLR_CYAN);

    /* 5. Perfect circle (w == h): magenta fill, no outline */
    CreateEllipse(5, 240, 130, 80, 80, CLR_NONE, CLR_MAGENTA);

    /* 6. Outline-only circle */
    CreateEllipse(6, 340, 130, 80, 80, CLR_LGREEN, CLR_NONE);

    /* Move element 1 to a new position after creation */
    ElemModifyBounds(1, 20, 220, -1, -1);

    MainWindowLoop(60, on_frame);
    TerminateWindow();
    return 0;
}
To animate a shape, call ElemModifyBounds from inside your on_every callback each frame, updating x or y based on GetElapsedTime() or delta_time.

Build docs developers (and LLMs) love