Drawing primitives let you paint geometric shapes and sprite graphics directly into an image element’s palette-indexed pixel buffer. All coordinates passed to primitives are canvas-relative —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.
(0, 0) is the top-left corner of the image element, not the window. Pixels outside the canvas bounds are silently clipped.
Primitives write to
img->data (the palette-indexed pixel buffer) but do not automatically call GUpdateImage. You must call GUpdateImage(id) after one or more primitive draws to propagate changes to the underlying XImage and have them appear on screen.GPrimitiveRect
id. The left and right edges and the top and bottom rows are drawn with the border color fg; interior pixels are filled with bg.
ID of an existing image element to draw into.
Left edge of the rectangle relative to the canvas top-left.
Top edge of the rectangle relative to the canvas top-left.
Width of the rectangle in pixels.
Height of the rectangle in pixels.
Palette index for the border/outline. Pass
-1 to skip drawing the outline (the bg color is used for all pixels in that case, because the implementation substitutes fg = bg when fg == -1).Palette index for the fill. Pass
-1 to leave interior pixels unchanged (transparent fill).GPrimitiveCircle
id. The circle is rasterized by iterating a bounding box and testing each pixel’s distance from the center. Border pixels are those whose squared distance falls within [(r-1)², r²]; fill pixels are everything inside r².
ID of an existing image element.
X coordinate of the circle center, relative to the canvas top-left.
Y coordinate of the circle center, relative to the canvas top-left.
Radius in pixels.
Palette index for the 1-pixel-wide border ring. Pass
-1 to skip drawing the border.Palette index for the filled interior. Pass
-1 to leave interior pixels unchanged. When both fg and bg are set, the border takes priority over the fill for border pixels.GPrimitiveLine
(x1, y1) to (x2, y2) using linear float stepping (not Bresenham). The number of steps equals max(|dx|, |dy|), with floating-point increments along each axis rounded to the nearest integer per step. Pixels outside the canvas are silently skipped.
ID of an existing image element.
X coordinate of the line start, relative to the canvas top-left.
Y coordinate of the line start, relative to the canvas top-left.
X coordinate of the line end, relative to the canvas top-left.
Y coordinate of the line end, relative to the canvas top-left.
Palette index for the line pixels.
GPrimitiveSprite
id. The sprite is decoded character by character; filled pixels use the color palette index, transparent pixels use palette index 0. Each logical pixel is rendered as a scale × scale block of physical pixels.
ID of an existing image element.
X coordinate of the sprite’s top-left corner in canvas coordinates.
Y coordinate of the sprite’s top-left corner in canvas coordinates.
Palette index used for all filled (
#) pixels in the sprite.RLE sprite string. See the RLE Sprite Format section below for the encoding rules.
Integer pixel scale factor.
1 renders each logical pixel as one physical pixel. 2 renders each logical pixel as a 2×2 block, effectively doubling the sprite size. 3 triples it, and so on.RLE Sprite Format
Sprites are described by compact run-length encoded strings. The decoder processes the string left to right, advancing an internal cursor that starts at(sx, sy) and moves right as pixels are placed.
| Token | Meaning |
|---|---|
# | Filled pixel — writes color at the cursor, then advances cursor right by scale. |
. | Transparent pixel — writes palette index 0 at the cursor, then advances cursor right by scale. |
$ | Newline — resets X to sx, advances Y down by scale (multiplied by an optional count). |
> | Skip right — advances cursor right by scale pixels (without writing), multiplied by an optional count. |
0–9 | Numeric prefix — sets a repeat count for the immediately following token or group. 5# places 5 filled pixels. |
[...] | Group — the content between brackets is treated as a repeatable sub-sequence. Prefix with a number to repeat: 3[#.] expands to #.#.#.. |
! | End of sprite — stops decoding immediately. |