Skip to main content

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.

The console element is a scrollable text terminal widget — useful for in-app logs, debug output, or REPL-style displays. It maintains an internal text buffer, handles word-wrap at the column boundary, and draws a proportional scrollbar on its right edge.

GCreateConsole

void GCreateConsole(int id, int x, int y, int cols, int rows, int clr)
Creates a console element. The rendered pixel dimensions are derived from cols and rows:
  • Width: cols * 9 + 17 px (9 px per character column + 17 px for the scrollbar area)
  • Height: rows * 15 + 10 px (15 px per row + 10 px padding)
id
int
required
Element slot index. If the slot is already occupied the existing element is deleted first.
x
int
required
Left edge of the console in window pixels.
y
int
required
Top edge of the console in window pixels.
cols
int
required
Number of character columns visible at one time. Text longer than cols characters on a single logical line is soft-wrapped onto the next visual line automatically.
rows
int
required
Number of visible text lines. Lines beyond rows are accessible by scrolling.
clr
int
required
Packed color byte for the console widget. High nibble = border palette index, low nibble = background palette index. For example, 0x07 gives a white (7) border on a black (0) background.

GConsolePrint

void GConsolePrint(int id, const char* format, ...)
Appends formatted text to the console’s internal buffer, following printf-style format strings. The rendered output is then available for display on the next GRenderWindow call.
id
int
required
Element slot index of an existing console element.
format
const char*
required
A printf-compatible format string. The formatted result is capped at 1024 characters per call (including the null terminator).
...
variadic
Optional arguments consumed by format, following standard printf conventions.
Character handling:
CharacterBehavior
\nStarts a new line.
\tExpanded to 4 spaces.
Printable ASCII (0x1B–0x7E)Displayed as-is.
Any other byteDisplayed as ?.
Auto-scroll: If the console was already scrolled to the very last line before the print, it automatically advances the scroll position to keep the newest content in view. If the user has scrolled up to review earlier output, the scroll position is not changed.

GConsoleClear

void GConsoleClear(int id)
Clears all text from the console’s internal buffer, resets the total line count to 0, and resets the scroll position to the top.
id
int
required
Element slot index of an existing console element.

Scrolling

The console responds to user input automatically when the mouse cursor is inside its bounds:
InputEffect
Scroll wheel upScroll up one line.
Scroll wheel downScroll down one line.
SpaceJump to the bottom (most recent output).
The scrollbar thumb height is proportional to the ratio of visible rows to total lines: max(9, (h - 6) * rows / total_lines) px, so it gives a visual indication of how much content is off-screen.

Example

// Create a 40-column, 10-row console with a white border on black background
GCreateConsole(0, 10, 10, 40, 10, 0x07);

// Inside a per-frame callback — print diagnostics each tick
void on_frame(int tick) {
    int player_x, player_y;
    // ... update game state ...
    GConsolePrint(0, "Frame %d: x=%d y=%d\n", tick, player_x, player_y);
}

// Clear the console on keypress
void on_key(int key) {
    if (key == 'c') GConsoleClear(0);
}
For high-frequency logging (e.g., every frame at 60 fps), consider printing only when values change, or throttling output to every N frames. Each GConsolePrint call appends to an unbounded std::string buffer — long-running sessions will grow memory usage and increase render time for line-wrapping.

Build docs developers (and LLMs) love