LWXGL windows are backed by a double-buffered Xlib pixmap. Each frame your code callsDocumentation 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.
GHandleWindowEvents to drain the event queue, then GRenderWindow to composite all visible elements onto the backbuffer and blit it to the screen. GSimpleWindowLoop handles this automatically when you don’t need manual frame control.
GCreateWindow
9x15 bitmap font, and creates the backbuffer pixmap. The window is mapped immediately and is non-resizable by default — XSizeHints are set so that both the minimum and maximum size equal w × h. Call GEnableResizing afterward to lift that constraint.
Width of the window in pixels.
Height of the window in pixels.
Title string displayed in the window’s title bar. Passed directly to
XStoreName.Background fill color as a palette index in the range 0–15. This is the color used to clear the backbuffer at the start of every
GRenderWindow call.| Value | Meaning |
|---|---|
0 | Success. |
1 | XOpenDisplay failed — no X11 display available. |
2 | Font load failed — the 9x15 bitmap font could not be found. |
3 | A window already exists. Only one window is supported per process. |
127 + i | Color allocation failed for palette index i. All previously allocated colors are freed before returning. |
GTerminateWindow
GCreateWindow. In order: deletes all registered UI elements, frees the font, frees the graphics context, frees the backbuffer pixmap, frees all 16 palette colors, destroys the window, and closes the display connection.
Example
GWindowShouldClose
- The WM sending a
WM_DELETE_WINDOWclient message. - A direct call to
GDeleteWindow. - The user pressing Ctrl + Escape.
1 when the window should close, 0 otherwise.
Example
GHandleWindowEvents
XPending / XNextEvent. Every pending event is dispatched to the appropriate internal handler before the function returns. Handles:
ButtonPress/ButtonRelease— mouse button state and UI element interaction.MotionNotify— cursor position tracking.LeaveNotify— resets cursor position to-1, -1when the pointer leaves the window.KeyPress/KeyRelease— keyboard state tracking and user key callback.ConfigureNotify— window resize (coalesces multiple events, recreates the backbuffer, fires the resize callback).ClientMessage— WM close protocol.
Call
GHandleWindowEvents once per frame, before GRenderWindow. Calling it multiple times per frame is safe but redundant since all pending events are consumed in a single call.GRenderWindow
- Fills the entire backbuffer with the background color set by
GSetWindowColor(or thebgcolpassed toGCreateWindow). - Draws every visible element whose
screenfield matches the active screen. - If a modal is open, draws the modal dialog on top.
- If the debug overlay is enabled (toggled with F12), draws the FPS counter and frame-time graph.
- Blits the completed backbuffer to the window via
XCopyArea.
GRenderWindow always clears the backbuffer first, so you do not need to manually erase previous frames.GSimpleWindowLoop
GHandleWindowEvents and GRenderWindow every frame, then invokes on_every, and sleeps just long enough to honour target_fps. The loop exits when GWindowShouldClose returns 1.
Frame timing uses std::chrono::steady_clock. If a frame runs long enough to fall two frame-periods behind, the internal time base is reset to prevent a catch-up spiral.
Desired frame rate cap. For example,
60 caps the loop at approximately 60 Hz.Callback invoked once per frame after events and rendering. Pass
NULL if you need no per-frame logic.tick— zero-indexed frame counter, incremented each frame.delta_time— elapsed seconds since the previous frame (e.g.0.01667at 60 fps).
GSimpleWindowLoop enables the debug overlay data collection automatically. Press F12 at runtime to toggle the overlay.GDeleteWindow
GWindowShouldClose returns 1 on the next check. Before setting the flag, if a delete handler was registered with GEventAttachDelete, it is called:
- If the handler returns 1, the close proceeds.
- If the handler returns 0, the close is blocked and the flag is not set.
GDeleteWindow does not free any resources. Call GTerminateWindow after the loop exits to perform the actual cleanup.GSetWindowTitle
XStoreName directly.
Null-terminated string to display in the title bar.
GSetWindowColor
GRenderWindow call. Takes effect on the very next rendered frame.
Palette index in the range 0–15.
GEnableResizing
PMinSize | PMaxSize size hints that GCreateWindow installs, allowing the window manager to resize the window freely. When the window is resized, GHandleWindowEvents detects the ConfigureNotify event, recreates the backbuffer pixmap at the new dimensions, and calls Resize with the new size.
Callback invoked whenever the window is resized. Receives the new width and height in pixels. Pass
NULL to allow resizing without a callback.Multiple rapid resize events within a single
GHandleWindowEvents call are coalesced — only the final dimensions are used to recreate the pixmap and fire the callback.GCaptureRegion
P6) image in a heap-allocated buffer. The backbuffer reflects the most recently rendered frame; call this after GRenderWindow to capture a complete frame.
The PPM header format is:
w × h × 3 bytes of raw RGB pixel data in row-major order.
Left edge of the capture rectangle in backbuffer coordinates.
Top edge of the capture rectangle in backbuffer coordinates.
Width of the capture rectangle in pixels.
Height of the capture rectangle in pixels.
Output parameter. Set to the total byte count of the returned buffer (PPM header + pixel data).
malloc-allocated unsigned char* buffer containing the PPM file data. The caller is responsible for calling free() on the returned pointer.
Example — saving a screenshot to disk
GSpawnModal
GHandleWindowEvents blocks all button clicks and key events from reaching UI elements or user callbacks — only the modal’s own click regions are active. The modal is dismissed when the user clicks a button.
Dialog style:
0— OK-only: a single “OK” button that invokeson_confirmand closes the modal.1— Confirm/Cancel: two buttons. “Confirm” invokeson_confirmand closes the modal. “Cancel” closes the modal without invoking the callback.
Message text displayed inside the dialog. Use
\n for line breaks.Callback invoked when the user clicks OK or Confirm. May be
NULL if you only need to inform the user without triggering an action.GQueryModalOpen
1 while a modal is displayed, 0 when no modal is open.
Example