This quickstart walks you through writing a complete LWXGL program from scratch. By the end you will have an X11 window containing a white text label and a styled button, running at 60 frames per second with a click handler — all in under 30 lines of C. The example also demonstrates the fixed-timestep game loop and the per-frame tick callback, giving you the foundation you need to build interactive applications or simple games on top of LWXGL.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.
Building a Hello-World Window
Include the header
LWXGL exposes its entire public API through a single header. After
make install the header lives at /usr/local/include/libLWXGL.h, which is on the default include path.Create the window
Call The fourth argument,
GCreateWindow before any other LWXGL function. It opens the X11 display, allocates the 16-colour palette, creates the backing pixmap, and maps the window to the screen.bgcol, is the palette index used to clear the window background each frame. 0 is Black.Return codes:| Value | Meaning |
|---|---|
0 | Success — window is open and ready |
1 | No X display — XOpenDisplay(NULL) returned NULL; check your DISPLAY environment variable |
2 | Font not found — the 9x15 bitmap font used for all text rendering was unavailable |
3 | Window already open — GCreateWindow was called a second time without calling GTerminateWindow first |
Add a text label
GCreateText registers a static text element. The element is drawn every frame by the render loop — you do not need to call anything else to keep it visible.id, x, y, color (palette index), text. The text is drawn using the built-in 9x15 bitmap font. Embed \n to create multi-line labels.Add a button
GCreateButton creates a labelled, interactive button. The three packed colour bytes — u (normal), hvr (hover), and p (pressed) — each encode a foreground palette index in their high nibble and a background palette index in their low nibble.on_click argument is a void (*)(void) function pointer called when the user releases the left mouse button while the cursor is inside the button bounds.The packed colour byte format is used by
GCreateButton and GCreateInput alike. In a byte 0xFB: the high nibble 0xF (decimal 15) is the foreground palette index (White) and the low nibble 0xB (decimal 11) is the background palette index (Light Cyan). Passing 0x00 sets both foreground and background to Black (index 0).Run the event loop
GSimpleWindowLoop blocks until the window is closed, calling GHandleWindowEvents and GRenderWindow every frame and sleeping between frames to honour the target FPS.void (*on_every)(int tick). Passing NULL disables it. The tick counter starts at 0 and increments by one each rendered frame.Complete Example
Compile and Run
Save the file ashello.c, then build and execute:
Button clicked! to standard output. Close the window (or press Ctrl+Esc) to exit.
Using the Per-Frame Tick Callback
When you need to run logic every frame — animating sprites, polling input, updating a game state — pass avoid (*)(int) callback as the second argument to GSimpleWindowLoop. The tick parameter starts at 0 and increments by one for each rendered frame, making it easy to schedule events at regular intervals.
GHandleWindowEvents and GRenderWindow have completed for that frame, so any element mutations you make inside on_frame take effect on the next rendered frame.
Handling Key Events
To respond to keyboard input, register a callback withGEventAttachKey. The callback receives the X11 keysym for printable characters or one of the GKey* constants for special keys.
libLWXGL.h:
| Constant | Value | Key |
|---|---|---|
GKeyLeft | 170 | Left arrow |
GKeyRight | 171 | Right arrow |
GKeyUp | 172 | Up arrow |
GKeyDown | 173 | Down arrow |
GKeyFnBase | 150 | Function key base (add key number for F1–Fn) |
GQueryKeyDown(int ch), which returns non-zero if that key is currently pressed.
Manual Event Loop
GSimpleWindowLoop is the recommended entry point for most applications. If you need to integrate LWXGL into an existing event loop or drive the render cycle at a variable rate, you can call GHandleWindowEvents() and GRenderWindow() manually and use GWindowShouldClose() as your loop condition: