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.

Every LWXGL frame follows a fixed pipeline: clear the back-buffer, render elements or run your callback (depending on rendering order), then flip to screen. These functions let you control that order, schedule work to run after a delay, and draw shapes or text directly from within your callback without creating persistent elements.

Constants

ORDER_* — Rendering Order

ConstantValueMeaning
ORDER_ELEM_SECOND0(Default) The on_every callback fires first; elements are drawn on top of anything you draw in the callback.
ORDER_ELEM_FIRST1Elements are drawn first; the on_every callback fires after, so callback drawing appears on top of elements.

Functions

SetRenderingOrder

Controls whether registered elements are drawn before or after the on_every callback in each frame. The default is ORDER_ELEM_SECOND, meaning elements appear on top.
void SetRenderingOrder(int order);
order
int
required
Either ORDER_ELEM_FIRST (1) or ORDER_ELEM_SECOND (0).
Call SetRenderingOrder before MainWindowLoop starts. Changing it mid-loop takes effect from the very next frame.

NewQueuedTask

Schedules a zero-argument function to be called after a specified number of seconds of elapsed loop time. Tasks are checked and dispatched once per frame, at the end of the frame in which their deadline is reached.
void NewQueuedTask(float run_after, void (*task)(void));
run_after
float
required
Number of seconds to wait before the task fires, measured from the moment NewQueuedTask is called (i.e., relative to the current GetElapsedTime() value).
task
void (*)(void)
required
Function to call when the delay elapses. The task runs once and is then removed from the queue.
Tasks can be queued from inside the on_every callback or from other tasks — the queue is safe to modify during iteration because dispatched tasks are erased after invocation.

GetElapsedTime

Returns the total elapsed time in seconds since MainWindowLoop began. The value is accumulated from the delta_time of each processed frame, so it reflects real wall-clock time minus any time spent waiting between frames.
float GetElapsedTime(void);
Returns a float in seconds. The value is 0.0 before MainWindowLoop is entered.

Immediate Drawing Functions

These functions draw directly to the back-buffer during the current frame and produce no persistent element. They are designed to be called from inside the on_every callback. Anything drawn here is cleared at the start of the next frame.

ImmediateText

Draws a string at the given position using the current font (9x15 or 9x15bold). Newline characters (\n) are supported; each subsequent line is offset by 15 pixels vertically. The y coordinate is shifted down by 11 pixels internally to align the font baseline.
void ImmediateText(int x, int y, const char* str, int color);
x
int
required
Left edge of the text in pixels, relative to the window origin.
y
int
required
Top edge of the text. The actual baseline is drawn at y + 11; subsequent lines step by 15 pixels each.
str
const char*
required
Null-terminated string to draw. Newline characters split the string into multiple lines.
color
int
required
Text color, one of the CLR_* palette constants.

ImmediateRect

Draws a filled and/or outlined rectangle. Either fg or bg can be CLR_NONE to skip the corresponding draw call.
void ImmediateRect(int x, int y, int w, int h, int fg, int bg);
x
int
required
Left edge of the rectangle in pixels.
y
int
required
Top edge of the rectangle in pixels.
w
int
required
Width in pixels.
h
int
required
Height in pixels.
fg
int
required
Border color (CLR_*), or CLR_NONE to draw no border.
bg
int
required
Fill color (CLR_*), or CLR_NONE to draw no fill (transparent interior).

ImmediateEllipse

Draws a filled and/or outlined ellipse inscribed in the given bounding box. Either fg or bg can be CLR_NONE.
void ImmediateEllipse(int x, int y, int w, int h, int fg, int bg);
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.
h
int
required
Height of the bounding box in pixels.
fg
int
required
Outline color (CLR_*), or CLR_NONE for no outline.
bg
int
required
Fill color (CLR_*), or CLR_NONE for no fill.

ImmediateLine

Draws a straight line segment between two points using XDrawLine.
void ImmediateLine(int x1, int y1, int x2, int y2, int color);
x1
int
required
X coordinate of the start point.
y1
int
required
Y coordinate of the start point.
x2
int
required
X coordinate of the end point.
y2
int
required
Y coordinate of the end point.
color
int
required
Line color, one of the CLR_* palette constants.

Code Example

#include "libLWXGL.h"

static int show_banner = 1;

static void hide_banner(void) {
    show_banner = 0;
}

static void on_frame(int tick, float dt) {
    /* Draw a real-time clock display using immediate functions */
    float t = GetElapsedTime();

    /* Background panel */
    ImmediateRect(10, 10, 200, 60, CLR_WHITE, CLR_BLACK);

    /* Elapsed-time readout */
    char buf[64];
    snprintf(buf, sizeof buf, "Time: %.2f s\nFrame: %d", t, tick);
    ImmediateText(18, 18, buf, CLR_LGREEN);

    /* Horizontal rule that moves with time */
    int x = (int)(t * 60) % 780;
    ImmediateLine(x, 80, x + 20, 80, CLR_YELLOW);

    if (show_banner) {
        ImmediateText(10, 120, "Banner hides in 3 seconds", CLR_LCYAN);
    }
}

int main(void) {
    CreateWindow(800, 200, "Immediate Drawing Demo", CLR_GRAY, FLAG_NONE);

    /* Draw elements on top of immediate drawings */
    SetRenderingOrder(ORDER_ELEM_SECOND);

    /* Hide the banner after 3 seconds */
    NewQueuedTask(3.0f, hide_banner);

    MainWindowLoop(60, on_frame);
    TerminateWindow();
    return 0;
}

Build docs developers (and LLMs) love