All primitive drawing functions write into the pixel buffer of an Image canvas element created withDocumentation 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.
GCreateImage. The pixel buffer stores one-byte palette indices per pixel — each value selects a colour from LWXGL’s internal colour table. After issuing one or more draw calls, invoke GUpdateImage to flush only the changed pixels to the screen. Coordinates passed to every primitive are canvas-relative: they are measured from the top-left corner of the image’s pixel buffer, not from the window origin.
GPrimitiveRect
id. The outermost 1-pixel border ring is painted with fg; the interior area is filled with bg. Any portion of the rectangle that falls outside the canvas bounds is silently clipped — no out-of-bounds writes occur.
If
fg is -1, it is internally promoted to the value of bg before rendering begins. This means the entire rectangle area — border and interior alike — is filled with bg, producing a solid filled rectangle with no separate border. Corner pixels always use the resolved fg value.Element ID of the Image canvas to draw into. Must have been created with
GCreateImage.X coordinate of the rectangle’s top-left corner, relative to the canvas origin.
Y coordinate of the rectangle’s top-left corner, relative to the canvas origin.
Width of the rectangle in pixels.
Height of the rectangle in pixels.
Palette index used for the 1-pixel border. Pass
-1 to promote fg to bg so the rectangle is fully filled with no distinct border.Palette index used to fill the interior. Pass
-1 to leave interior pixels unchanged (only the border is drawn, provided fg is not also -1).Example
GPrimitiveCircle
(cx, cy) with radius r pixels. The outermost ring of pixels — those satisfying (r-1)² ≤ dx²+dy² ≤ r² — is painted with fg. All remaining pixels inside the circle are filled with bg. Pixels outside the canvas bounds are clipped.
Element ID of the Image canvas to draw into.
X coordinate of the circle’s centre, relative to the canvas origin.
Y coordinate of the circle’s centre, relative to the canvas origin.
Radius of the circle in pixels.
Palette index for the 1-pixel border ring. Pass
-1 to skip border rendering.Palette index for the filled interior. Pass
-1 to skip fill rendering (outline-only circle).Example
GPrimitiveLine
(x1, y1) to (x2, y2) using floating-point increments: the axis with the larger delta drives the step count, and the other axis advances by a fractional increment each step, rounded to the nearest integer. This produces a connected, single-pixel-wide line. Pixels that fall outside the canvas bounds are skipped.
The number of steps is
max(|x2−x1|, |y2−y1|), so every pixel along the dominant axis is guaranteed to be written exactly once. For perfectly horizontal or vertical lines, this is equivalent to a simple scanline fill.Element ID of the Image canvas to draw into.
X coordinate of the line’s start point, relative to the canvas origin.
Y coordinate of the line’s start point, relative to the canvas origin.
X coordinate of the line’s end point, relative to the canvas origin.
Y coordinate of the line’s end point, relative to the canvas origin.
Palette index used to paint every pixel of the line.
Example
GPrimitiveSprite
(sx, sy). Each logical sprite pixel expands to a scale × scale block of canvas pixels. Filled pixels write the given color palette index; transparent pixels write palette index 0 (Black).
Sprite coordinates
sx and sy are canvas-relative, not window-relative. They are measured from the top-left corner of the image pixel buffer created with GCreateImage.Element ID of the Image canvas to draw into.
X coordinate of the sprite’s top-left corner within the canvas.
Y coordinate of the sprite’s top-left corner within the canvas.
Palette index written for every filled (
#) pixel in the sprite.Null-terminated RLE sprite string. See the RLE Token Reference below for the full grammar.
Pixel scale factor.
1 renders each sprite pixel as one canvas pixel; 2 renders each sprite pixel as a 2×2 block; N renders each sprite pixel as an N×N block.RLE Token Reference
The sprite string is parsed left-to-right. A decimal digit prefix accumulates a repeat count that is consumed by the very next non-digit token. Tokens may be nested inside bracket groups.| Token | Meaning |
|---|---|
# | Filled pixel. Writes color to the current canvas position and advances X by scale. |
. | Transparent pixel. Writes palette index 0 (Black) and advances X by scale. |
$ | Newline. Resets X to sx and advances Y by scale × (repeat count, default 1). |
> | Column skip. Advances X by scale without writing any colour. Prefix with a count to skip multiple columns: 3> advances X by 3 × scale. |
N… | Digit prefix / repeat count. One or more decimal digits before any token repeat that token N times: 5# draws five filled pixels; 3> skips three columns. |
[…] | Repeat group. Tokens enclosed in brackets form a group. Prefix the opening bracket with a count to repeat the whole group: 3[#.] expands to #.#.#.. |
! | Terminator. Stops parsing immediately. Any characters after ! are ignored. |
Cross Sprite Example
$. The prefix 2. expands to .., the middle # is the vertical bar pixel, and the second 2. closes the row. Row three uses 5# to draw the full horizontal bar in a single token.
Complete Example
The snippet below creates a 320×240 image canvas, paints a background, draws a circle, draws a diagonal line across the scene, and flushes everything to the screen in oneGUpdateImage call.