LWXGL exposes a small set of C functions for creating and managing a single X11 window, driving a frame loop, rendering registered elements to a double-buffered back buffer, and displaying modal dialogs. All window state is held internally by the library; your application interacts with it exclusively through the functions documented on this page.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.
Window Lifecycle
These functions control the creation and orderly teardown of the window and all associated X11 resources.GCreateWindow
w × h pixels, sets its title to name, and records bgcol as the background palette index used by GRenderWindow. The function connects to the X display, loads the 9x15 bitmap font, allocates all 16 palette colors from the default colormap, creates a graphics context and a back-buffer pixmap, and registers WM_DELETE_WINDOW so that the close button can be intercepted. Minimum and maximum size hints are set to w × h, so the window cannot be resized by the user.
Width of the window in pixels.
Height of the window in pixels.
Null-terminated string used as the window title.
Background palette index used to clear the back buffer each frame. Must be a value in the range 0–15 inclusive.
| Value | Meaning |
|---|---|
0 | Success — window created and mapped. |
1 | Could not connect to the X display (XOpenDisplay returned NULL). |
2 | The bitmap font 9x15 was not found on the X server. |
3 | A window is already open (only one window is supported at a time). |
127 + i | XAllocColor failed for palette color index i (0–15). Values in the range 127–142. |
GTerminateWindow
Event Loop
These functions implement the per-frame event-loop pattern. You can either drive the loop yourself usingGWindowShouldClose, GHandleWindowEvents, and GRenderWindow, or delegate entirely to GSimpleWindowLoop.
GWindowShouldClose
closing flag. Use the return value as the exit condition of a manual while loop.
1 when the window has been signalled to close — either because the user clicked the close button or because GDeleteWindow was called. 0 otherwise.GHandleWindowEvents
XPending / XNextEvent in a loop and dispatches each pending event to its registered handler. This covers pointer motion, button press/release, key press/release, cursor-leave (LeaveNotify), expose events, and the WM_DELETE_WINDOW client message. Must be called once per frame when using a manual loop; GSimpleWindowLoop calls it automatically.
GRenderWindow
- Fills the back-buffer pixmap with the background palette color set in
GCreateWindow. - Iterates over all registered elements in ID order and calls each element’s renderer.
- If a modal is active, draws it on top of all elements.
- If the debug overlay is enabled (activated automatically by
GSimpleWindowLoop), draws the FPS and frame-time overlay. - Blits the back buffer to the visible window with
XCopyAreaand callsXSync.
GSimpleWindowLoop
GHandleWindowEvents()— drains the X11 event queue.GRenderWindow()— renders the frame.on_every(tick)— calls your per-frame callback with the running tick counter.
Desired frames per second. The loop derives the frame period as
1 000 000 / target_fps microseconds.Per-frame callback invoked after rendering. Receives the zero-based tick counter that increments once per rendered frame. Pass
NULL if no per-frame callback is needed.GSimpleWindowLoop blocks the calling thread until GWindowShouldClose returns 1. Place all setup code (element registration, event attachment) before calling this function, and all cleanup code (including GTerminateWindow) after it returns.Window Close Control
GDeleteWindow
closing flag to 1. If a delete callback has been registered with GEventAttachDelete, that callback is invoked first and its return value is used as the new value of closing — allowing the callback to veto the close by returning 0.
Modal Dialogs
GSpawnModal
GRenderWindow on top of all other elements each frame.
Controls which buttons appear in the dialog.
| Value | Buttons shown |
|---|---|
0 | OK only |
1 | OK and Cancel |
Null-terminated message string displayed inside the dialog. Use
\n to break the text across multiple lines. Each line is rendered up to a maximum of approximately 31 characters before it is clipped.Callback invoked when the user clicks OK. Pass
NULL if no action is needed on confirmation. The callback is not called when Cancel is clicked.The modal is dismissed automatically when the user clicks either button. You do not need to call any function to close it manually.
GQueryModalOpen
1 if a modal dialog is currently displayed; 0 otherwise.