By the end of this page you will have a running LWXGL application that opens a 640×400 X11 window, displays a text label, and shows a clickable button — all from a single C source file. The complete example is under 25 lines and requires no build system beyond a singleDocumentation 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.
gcc invocation.
Build a Hello World Window
Include the header and set up your compile command
LWXGL’s entire public API is exposed through one header. Add it to your source file:Compile your program by linking against No additional
-lLWXGL:-I or -L flags are needed when LWXGL is installed to the default system paths via make install.Create the window
Call The four parameters are:
GCreateWindow before doing anything else. It opens the X11 display connection, allocates the palette colors, and maps a fixed-size window on screen:| Parameter | Type | Description |
|---|---|---|
w | int | Window width in pixels |
h | int | Window height in pixels |
name | const char* | Window title bar text |
bgcol | int | Background color palette index (0–15) |
GCreateWindow returns 0 on success. Other return values indicate a specific failure:1— No X11 display available ($DISPLAYnot set or server unreachable)2— Required bitmap font (9x15) could not be loaded3— A window is already open (only one window is supported at a time)
Add UI elements
UI elements are identified by an integer
The three states map to:
id you assign. Add a text label and a button:GCreateText(id, x, y, color, text) — renders a static text string at position (x, y) in the given palette color index.GCreateButton(id, x, y, w, h, u, hvr, p, label, onclick) — creates a labeled button with three packed color bytes for its visual states and a callback function pointer.Packed color byte format
Theu, hvr, and p parameters each encode two palette indices in a single byte using the nibble convention used throughout LWXGL:- High nibble (
>> 4): border / outline color index - Low nibble (
& 0x0F): fill / background color index
| Value | High nibble | Low nibble | Meaning |
|---|---|---|---|
0x70 | 7 = Light Gray | 0 = Black | Light gray border, black fill |
0x80 | 8 = Dark Gray | 0 = Black | Dark gray border, black fill (hover) |
0x90 | 9 = Light Blue | 0 = Black | Light blue border, black fill (pressed) |
u = unpressed/idle, hvr = mouse hover, p = mouse pressed.Run the frame-capped loop
GSimpleWindowLoop drives the entire event-dispatch and render cycle at the requested frame rate. It blocks until the window is closed:- First argument: target frames per second (here, 60 FPS)
- Second argument: optional
void (*on_every)(int tick)callback invoked once per frame. PassNULLif you have no per-frame logic.
Complete Example
Button clicked! to your terminal. Close the window to exit.
Next, read the Core Concepts to understand the window lifecycle, color palette, and element system in depth.