Every LWXGL application follows the same three-phase lifecycle: create a window and allocate its X11 resources, drive the render loop to process events and paint frames, then tear down the window cleanly when the user is done. Understanding each phase and the functions involved lets you build anything from a simple game to a full desktop utility.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.
Creating a Window
GCreateWindow opens the X11 display connection, loads the built-in font, allocates the 16-color palette, and maps the window on screen. All other LWXGL calls assume a window has been successfully created first.
| Parameter | Type | Description |
|---|---|---|
w | int | Window width in pixels |
h | int | Window height in pixels |
name | const char * | Title bar text |
bgcol | int | Palette index (0–15) used to clear the background each frame |
| Code | Meaning |
|---|---|
0 | Success — window is open and ready |
1 | Display unavailable — XOpenDisplay failed (no $DISPLAY set, or no X server running) |
2 | Font not found — the built-in 9x15 bitmap font could not be loaded |
3 | Window already open — GCreateWindow was called a second time without GTerminateWindow |
127 + i | Color allocation failure for palette index i — the X server’s colormap is full |
Check the return code
Always inspect the return value before proceeding. A non-zero result means no window was opened and the rest of the API is unavailable.
Enter the render loop
Once
GCreateWindow returns 0, enter either GSimpleWindowLoop or your own manual loop.Window size is fixed at creation time. LWXGL sets
PMinSize and PMaxSize hints to the same values as w and h, preventing the user from resizing the window through the window manager.The Simple Loop
GSimpleWindowLoop is the easiest way to drive your application. It manages timing, handles events, renders each frame, and calls your callback — all at a steady target frame rate.
- Calls
GHandleWindowEvents()to drain the X11 event queue. - Calls
GRenderWindow()to paint the back-buffer and flip it to the screen. - Calls
on_every(tick)wheretickis a monotonically increasing counter that starts at 0 and increments by 1 each frame.
NULL as on_every if you only need the loop to render static elements without any per-frame logic.
The Manual Loop Pattern
For full control over event handling and rendering order, drive the loop yourself using the three building-block functions:- When to use GSimpleWindowLoop
- When to use the manual loop
Use
GSimpleWindowLoop whenever you want a consistent frame rate with minimal boilerplate. It handles sleep/yield logic so you do not have to.Closing the Window
LWXGL distinguishes between requesting a close and freeing resources.GDeleteWindow()
Signals that the window should close. If a delete callback has been attached via
GEventAttachDelete, that callback is invoked first — it can return 0 to cancel the close or 1 to confirm it. If no callback is attached, the close is confirmed immediately. After confirmation, GWindowShouldClose() begins returning 1.GTerminateWindow()
Frees all X11 resources: destroys all elements, unloads the font, frees the GC, pixmaps, palette colors, the window itself, and closes the display connection. Call this once after the render loop exits — never call it while the loop is still running.
Debug Overlay
GSimpleWindowLoop activates a built-in debug overlay that you can toggle at runtime by pressing F12. The overlay displays a small panel in the top-left corner of the window showing:
- FT — average frame time in microseconds over the last 60 frames.
- FPS — instantaneous frames-per-second.
GSimpleWindowLoop; it is not drawn in a manual loop unless you call GRenderWindow from within GSimpleWindowLoop implicitly.
You can also close the window at any time by pressing Ctrl+Escape, which calls GDeleteWindow() — invoking the registered delete callback if one is attached.
Modal Dialogs
LWXGL includes a simple built-in modal dialog system viaGSpawnModal. Modals pause all button, checkbox, and key-callback interactions until dismissed. See the Window API Reference for full details on GSpawnModal and GQueryModalOpen.