Primitive drawing functions operate directly on the pixel buffer of an image canvas element. All functions take an elementDocumentation 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.
id as their first argument and write palette indices into the canvas’s flat byte buffer. None of them call GUpdateImage automatically — call it after drawing to push changes to the screen.
All primitives clip silently: pixels that fall outside the canvas bounds are skipped without error.
GPrimitiveRect
fg controls the 1-pixel border; bg controls the interior fill. Either can be omitted by passing -1.
When fg is -1, it is set equal to bg before drawing, producing a solid filled rectangle with no distinct border. When bg is -1, interior pixels are left untouched (transparent).
ID of the target image canvas element.
Left edge of the rectangle within the canvas.
Top edge of the rectangle within the canvas.
Width in pixels.
Height in pixels.
Border color as a palette index. Pass
-1 to draw no border (the border color will instead match bg, producing a solid fill).Fill color as a palette index. Pass
-1 to leave interior pixels unchanged.GPrimitiveCircle
(x, y) is on the border when (r-1)² ≤ dx² + dy² ≤ r². Interior pixels satisfy dx² + dy² ≤ r² and are painted with bg when it is not -1.
Border pixels take priority over fill pixels when both conditions are satisfied.
ID of the target image canvas element.
X coordinate of the circle center within the canvas.
Y coordinate of the circle center within the canvas.
Radius in pixels.
Border color as a palette index. Pass
-1 to draw no border.Fill color as a palette index. Pass
-1 to leave interior pixels unchanged.GPrimitiveLine
max(|dx|, |dy|) where dx = x2 - x1 and dy = y2 - y1. At each step, x and y are incremented by dx/steps and dy/steps respectively, and the nearest integer pixel is painted. This produces results equivalent to Bresenham’s line algorithm. Pixels outside the canvas bounds are skipped.
ID of the target image canvas element.
X coordinate of the start point within the canvas.
Y coordinate of the start point within the canvas.
X coordinate of the end point within the canvas.
Y coordinate of the end point within the canvas.
Palette index (0–15) for the line pixels.
GPrimitiveSprite
color argument sets the foreground palette index used for # pixels. The scale factor magnifies each logical pixel into a scale × scale block of canvas pixels. Out-of-bounds pixels are clipped.
ID of the target image canvas element.
Left edge of the sprite within the canvas. This X origin is restored at each
$ (row advance).Top edge of the sprite within the canvas.
Palette index (0–15) used to draw
# pixels.Null-terminated RLE sprite string (see format table below).
Pixel scale factor.
1 = 1:1, 2 = each logical pixel becomes a 2×2 block, etc.Sprite RLE Format
| Character | Meaning |
|---|---|
# | Draw one pixel in color and advance X by scale. |
. | Draw one pixel in color 0 (black) and advance X by scale. |
$ | Move to the start of the next row: reset X to sx, advance Y by scale. Multiple $ tokens advance multiple rows. |
> | Advance X by scale without drawing (transparent skip). |
[...] | Repeat the enclosed pattern. Combine with a leading digit to repeat N times: 3[#.] = #.#.#.. Groups can be nested. |
N (digit) | Repeat the immediately following character or [...] group N times. Multi-digit counts are supported (12# = 12 filled pixels). |
(sx, sy). Each $ resets X to sx and advances Y by one row (scale pixels). The > and blank regions leave underlying canvas pixels unchanged.
Examples