The window API covers creating and destroying the X11 window, running the frame loop, spawning modal dialogs, managing the 16-color palette, and forcing image redraws. AllDocumentation 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.
G* functions must be called after a successful GCreateWindow, except where noted.
GCreateWindow
9x15 bitmap font, and allocates all 16 palette colors in the default X11 colormap. The window is fixed-size — it cannot be resized by the user. Must be called before any other G* function.
Width of the window in pixels.
Height of the window in pixels.
String displayed in the window title bar.
Background palette index (0–15). This color fills the window each frame before elements are rendered.
0 on success. Error codes:
| Code | Meaning |
|---|---|
1 | XOpenDisplay failed — no X11 display available. |
2 | Font load failed — 9x15 bitmap font not found. |
3 | A window is already open. |
GTerminateWindow
GCreateWindow and any subsequent element-creation calls. Specifically:
- Deletes all registered UI elements.
- Frees the X11 font, GC, back-buffer pixmap, and stipple pixmap.
- Frees all 16 allocated X11 colors from the colormap.
- Destroys the window and closes the display connection.
GSimpleWindowLoop returns, or after your manual loop ends).
GWindowShouldClose
1 when a window-close has been requested and accepted, 0 otherwise. Use this as the exit condition for a manual event loop.
Returns: 1 if the window should close, 0 if it should keep running.
GHandleWindowEvents
- Expose — triggers an immediate render.
- MotionNotify / LeaveNotify — updates the tracked cursor position.
- ButtonPress / ButtonRelease — updates
mouse_down, routes clicks to widgets orGEventAttachClickcallback. - KeyPress / KeyRelease — updates the
pressed_keysarray, routes characters to input/console elements orGEventAttachKeycallback. - ClientMessage — handles
WM_DELETE_WINDOW(close button).
GRenderWindow.
GRenderWindow
- Fills the back-buffer pixmap with the background palette color.
- Renders all non-NULL visible elements in ascending ID order.
- Draws any active modal dialog on top.
- If the debug overlay is enabled (toggled with F12 inside
GSimpleWindowLoop), draws the FPS and frame-time graph. - Blits the back-buffer to the screen using
XCopyAreaand flushes withXSync.
GHandleWindowEvents.
GDeleteWindow
- If
GEventAttachDeletehas been called, the registeredon_exit()callback is invoked. Its return value becomes the close flag: return1to allow the close,0to cancel it. - If no delete callback is registered, the close flag is set to
1immediately.
WM_DELETE_WINDOW handler when the user clicks the window’s × button, and also on Ctrl+Escape. You can call it directly to trigger a programmatic close.
GSimpleWindowLoop
GWindowShouldClose() returns 1. Each frame:
- Calls
GHandleWindowEvents(). - Calls
GRenderWindow(). - Calls
on_every(tick)if non-NULL, wheretickis a monotonically incrementing counter starting at0.
std::chrono::steady_clock with sleep/yield to achieve the requested frame rate without busy-waiting.
The F12 key toggles the debug overlay (FPS counter and 60-frame work-time graph) while the loop is running.
Desired frames per second (e.g.
60).Per-frame callback receiving the current
tick count. Pass NULL to skip.GSpawnModal
Dialog type:
0 = informational (OK button only); 1 = confirmation (OK + Cancel buttons).Message string shown in the dialog body. Use
\n for line breaks.Callback invoked when the user clicks OK. Pass
NULL if no action is needed.GQueryModalOpen
1 if a modal dialog is currently displayed, 0 otherwise.
Useful for suppressing custom logic that should not run while the user is interacting with a dialog.
GRedrawAllImages
255). This triggers GUpdateImage internally for each image element.
Called automatically by GPaletteModify (when redraw is non-zero) and by GPaletteReset. You only need to call it directly if you modify image pixel data outside of those functions and need to guarantee a complete refresh.
GPaletteQuery
idx back from the X11 colormap.
Palette index to query, in the range
0–15.Output pointer for the red channel (0–255).
Output pointer for the green channel (0–255).
Output pointer for the blue channel (0–255).
GPaletteModify
idx with a new RGB color. Frees the old X11 color allocation and allocates the new one in the default colormap.
Palette index to modify, in the range
0–15.New red channel value (0–255).
New green channel value (0–255).
New blue channel value (0–255).
Pass
1 to call GRedrawAllImages() after the update so image elements reflect the new color immediately. Pass 0 to skip.GPaletteReset
GRedrawAllImages(). The default palette is:
| Index | Name | RGB |
|---|---|---|
| 0 | Black | (0, 0, 0) |
| 1 | Dark Blue | (3, 3, 173) |
| 2 | Dark Green | (0, 170, 0) |
| 3 | Dark Cyan | (0, 168, 168) |
| 4 | Dark Red | (186, 6, 6) |
| 5 | Dark Magenta | (168, 0, 168) |
| 6 | Orange | (230, 126, 34) |
| 7 | Light Gray | (168, 168, 168) |
| 8 | Dark Gray | (85, 87, 83) |
| 9 | Light Blue | (87, 87, 255) |
| 10 | Light Green | (85, 255, 85) |
| 11 | Light Cyan | (96, 240, 240) |
| 12 | Light Red | (255, 85, 85) |
| 13 | Light Magenta | (240, 84, 240) |
| 14 | Yellow | (244, 242, 54) |
| 15 | White | (255, 255, 255) |