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.

All four primitive functions draw directly into the pixel buffer of an existing image element created with GCreateImage. They modify the element’s internal data buffer in memory only — call GUpdateImage(id) after drawing to flush your changes to the screen.
All primitive functions write to the image’s data buffer — none of them call GUpdateImage themselves. You must call GUpdateImage(id) explicitly to make drawn content visible on screen.

GPrimitiveRect

void GPrimitiveRect(int id, int x, int y, int w, int h, int fg, int bg)
Draws a rectangle into the image element identified by id.
  • id — element ID of the target image canvas (must have been created with GCreateImage).
  • x, y — top-left corner of the rectangle in image-local pixel coordinates.
  • w, h — width and height of the rectangle in pixels.
  • fg — palette index for the 1-pixel-wide border. Pass -1 to draw no border (the border color falls back to bg internally, so the full area receives the fill color instead).
  • bg — palette index for the interior fill. Pass -1 to leave interior pixels untouched (transparent/skip).
Pixels that fall outside the image bounds are clipped silently — no error is produced. Behavior notes:
  • The border is always exactly 1 pixel wide (the outermost row/column of the bounding rectangle).
  • If fg == -1, the border columns/rows are drawn with bg instead (the fill covers the entire rectangle area).
  • If both fg and bg are -1, no pixels are written.

GPrimitiveCircle

void GPrimitiveCircle(int id, int cx, int cy, int r, int fg, int bg)
Draws a filled circle into the image element identified by id.
  • id — element ID of the target image canvas.
  • cx, cy — center of the circle in image-local pixel coordinates.
  • r — radius in pixels.
  • fg — palette index for the 1-pixel-wide circular border. Pass -1 to draw no border.
  • bg — palette index for the interior fill. Pass -1 to draw no fill.
Out-of-bounds pixels are skipped silently. Behavior notes:
  • The border ring is defined as the set of pixels satisfying (r-1)² ≤ dx²+dy² ≤ r². It is always 1 pixel wide.
  • fg takes priority on border pixels: if fg != -1, border pixels are painted with fg, and bg is only applied to strictly interior pixels (pixels where dx²+dy² < (r-1)²).
  • If fg == -1 and bg != -1, all pixels within the circle radius (including the outermost ring) receive bg.

GPrimitiveLine

void GPrimitiveLine(int id, int x1, int y1, int x2, int y2, int color)
Draws a 1-pixel-wide straight line from (x1, y1) to (x2, y2) into the image element identified by id.
  • id — element ID of the target image canvas.
  • x1, y1 — start point in image-local pixel coordinates.
  • x2, y2 — end point in image-local pixel coordinates.
  • color — palette index to use for all line pixels.
Algorithm: Linear interpolation stepping max(|dx|, |dy|) times, incrementing x and y by dx/steps and dy/steps per step, rounding to the nearest pixel at each step. This produces a clean 1-pixel line at any angle. Pixels that land outside the image bounds are skipped.

GPrimitiveSprite

void GPrimitiveSprite(int id, int sx, int sy, int color, const char* sprite, int scale)
Draws a run-length encoded (RLE) sprite into the image element identified by id.
  • id — element ID of the target image canvas.
  • sx, sy — top-left origin of the sprite in image-local pixel coordinates.
  • color — palette index used for foreground (#) pixels.
  • sprite — null-terminated RLE sprite string (see format below).
  • scale — integer pixel scale factor; each logical sprite pixel is drawn as a scale×scale block.

RLE Sprite Format

The sprite string is parsed left-to-right as a sequence of tokens. An optional decimal integer prefix on any token repeats that token (or group) that many times.
TokenMeaning
#Draw one foreground pixel block (color palette index) and advance x by scale.
.Draw one background pixel block (palette index 0) and advance x by scale.
$Newline — reset x to sx and advance y by scale (one row down). With a numeric prefix N, advances y by N × scale rows.
>Skip one pixel column (advance x by scale) without writing any pixel.
N<token>Repeat <token> exactly N times (e.g. 3# draws three foreground pixels).
N[pattern]Repeat pattern exactly N times. Brackets are nestable.
!Stop parsing immediately.
Sprite string examples:
// 3×3 solid filled square at scale 1:
"3[3#$]"

// Plus/cross shape (5 wide, 3 tall) at scale 2, with gaps on the sides:
">2#$5#$>2#"

// Alternating checkerboard row (5 pairs):
"5[#.]"

// Sparse row: 2 pixels, skip 1, 2 more pixels:
"2#>2#"

Full Example — Target Reticle

GCreateImage(0, 0, 0, 200, 200);
GClearImage(0, 0);

// outer ring: white border, no fill
GPrimitiveCircle(0, 100, 100, 40, 15, -1);
// inner filled circle: light red
GPrimitiveCircle(0, 100, 100, 10, 12, 12);

// crosshair lines (left, right, top, bottom gaps around the center circle)
GPrimitiveLine(0,  60, 100,  85, 100, 15);
GPrimitiveLine(0, 115, 100, 140, 100, 15);
GPrimitiveLine(0, 100,  60, 100,  85, 15);
GPrimitiveLine(0, 100, 115, 100, 140, 15);

GUpdateImage(0);

Build docs developers (and LLMs) love