The Window API provides everything needed to open an X11 window, drive a frame loop, show modal dialogs, and tear down all resources on exit. Most programs callDocumentation 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.
GCreateWindow once, register callbacks, then hand control to GSimpleWindowLoop — but the lower-level GHandleWindowEvents and GRenderWindow are also available for manual loop control.
GCreateWindow
name. The background color used when the window is cleared each frame is the palette index bgcol.
Width of the window in pixels. The window manager is instructed to treat this as both the minimum and maximum width, so the window cannot be resized by the user.
Height of the window in pixels. Treated as a fixed height for the same reason.
Window title string passed to
XStoreName. May be NULL-free; passed as-is to X11.Palette index (0–15) used to fill the background at the start of every
GRenderWindow call.0 on success. See the Return Codes table at the bottom of this page for all other values.
GSimpleWindowLoop
GWindowShouldClose() returns 1. Each frame calls GHandleWindowEvents(), then GRenderWindow(), then invokes on_every with the current tick counter. The loop tracks real elapsed time to maintain the requested frame rate, sleeping when ahead and skipping catch-up if more than two frames behind.
Desired frames per second. The frame period is computed as
1,000,000 / target_fps microseconds.Called once per frame after events are handled and the scene is rendered. The
int argument is the current tick count (an internal unsigned long long cast to int on each call — wraps at INT_MAX). May be NULL.GSimpleWindowLoop enables the debug metrics collection used by the F12 overlay. If you write a manual loop, the overlay values will remain at zero.GHandleWindowEvents
GSimpleWindowLoop. It must be called at least once per frame to keep the window responsive and to update mouse/keyboard state.
GRenderWindow
- Fills the back buffer with the
bgcolpalette color. - Iterates the element list and calls the appropriate renderer for each non-NULL element.
- If a modal is active, draws the modal overlay on top.
- If the debug overlay is enabled (F12 pressed while inside
GSimpleWindowLoop), draws the FPS/frame-time panel. - Calls
XCopyAreato blit the back buffer to the window andXSyncto flush.
GWindowShouldClose
1 when the window has been flagged to close (either by the WM close button, GDeleteWindow, or a delete handler returning 1). Returns 0 otherwise. Use this as the loop condition in a manual frame loop.
GDeleteWindow
GEventAttachDelete, it is called and its return value sets the closing flag. If no handler is registered, closing is set to 1 directly. This is also called internally when the user presses Ctrl+Escape or clicks the WM close button.
GDeleteWindow does not free resources — it only sets the close flag. Always call GTerminateWindow() after the loop exits to release X11 resources.GTerminateWindow
GSimpleWindowLoop (or your manual loop) exits.
GSpawnModal
1).
0 — OK-only dialog. 1 — OK / Cancel dialog. Clicking OK calls on_confirm; clicking Cancel (type 1 only) dismisses without calling on_confirm.Message text. Supports
\n newlines; lines are hard-wrapped at 31 characters by the renderer.Callback invoked when the user confirms. May be
NULL.GQueryModalOpen
1 if a modal dialog is currently active and being displayed, 0 otherwise. Useful for suppressing application-side input processing while a modal is open.
GRedrawAllImages
4), invalidates its shadow buffer by setting all bytes to 255 and calls GUpdateImage to force a complete pixel-by-pixel repaint. Called automatically by GPaletteModify (when redraw != 0) and GPaletteReset. You can also call it manually if you need to force all image canvases to re-render after a bulk palette change.
Return Codes
The following codes are returned byGCreateWindow:
| Code | Meaning |
|---|---|
0 | Success — window created and ready. |
1 | No X11 display found (XOpenDisplay returned NULL). Check that $DISPLAY is set. |
2 | The 9x15 bitmap font could not be loaded. The font must be available in the X server’s font path. |
3 | A window already exists. GCreateWindow cannot be called twice in the same process without calling GTerminateWindow first. |
127 + i | Color allocation failed for palette entry i (rare; indicates the X server colormap is full). |