All four primitive functions draw directly into the pixel buffer of an existing image 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. 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
id.
id— element ID of the target image canvas (must have been created withGCreateImage).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-1to draw no border (the border color falls back tobginternally, so the full area receives the fill color instead).bg— palette index for the interior fill. Pass-1to leave interior pixels untouched (transparent/skip).
- 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 withbginstead (the fill covers the entire rectangle area). - If both
fgandbgare-1, no pixels are written.
GPrimitiveCircle
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-1to draw no border.bg— palette index for the interior fill. Pass-1to draw no fill.
- The border ring is defined as the set of pixels satisfying
(r-1)² ≤ dx²+dy² ≤ r². It is always 1 pixel wide. fgtakes priority on border pixels: iffg != -1, border pixels are painted withfg, andbgis only applied to strictly interior pixels (pixels wheredx²+dy² < (r-1)²).- If
fg == -1andbg != -1, all pixels within the circle radius (including the outermost ring) receivebg.
GPrimitiveLine
(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.
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
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 ascale×scaleblock.
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.| Token | Meaning |
|---|---|
# | 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. |