Skip to content

SDL_Renderer

A 2D rendering context using the SDL renderer API. Freed automatically.

draw_color(color) function

Set the render draw color for subsequent primitive calls (rect, line, etc.).

color: [r, g, b, a] in 0..1.

Returns: None

present() function

Display whatever has been rendered (swap buffers). Must be called each frame.

Returns: None

clear() function

Clear the current render target with the renderer's draw color.

Returns: None

rect(rectOrArray, color) function

Draw one or more outlines of rectangles.

rectOrArray: A single rect {x,y,w,h} or an array of rects.

color: Optional [r,g,b,a]. If provided, overrides current draw color.

Returns: None

fillrect(rectOrArray, color) function

Fill one or more rectangles with the renderer's current color or an optional override.

rectOrArray: A single rect {x,y,w,h} or an array of rects.

color: Optional [r,g,b,a].

Returns: None

line(points, color) function

Draw a sequence of lines connecting points in an array.

points: An array of [x,y] points. Lines connect consecutive points.

color: Optional [r,g,b,a].

Returns: None

point(points, color) function

Draw a list of points (pixels).

points: An array of [x,y] positions.

color: Optional [r,g,b,a].

Returns: None

load_texture(surface) function

Create an SDL_Texture from a given SDL_Surface for use with this renderer.

surface: An SDL_Surface.

Returns: An SDL_Texture object.

texture(tex, dstRect, srcRect, color) function

Draw a texture onto the render target.

tex: The SDL_Texture to draw.

dstRect: The destination rect {x, y, w, h}.

srcRect: Optional portion of the texture to draw {x, y, w, h}.

color: Optional color mod [r,g,b,a].

Returns: None

slice9(tex, dstRect, edges, srcRect) function

Draw a texture with 9-slice scaling. The argument includes edges {l, r, t, b} for the corners/borders that remain unscaled. The rest is tiled or stretched.

tex: The SDL_Texture.

dstRect: Destination region {x, y, w, h}.

edges: {l, r, t, b} for corner sizes in pixels.

srcRect: Optional portion in the texture.

Returns: None

tile(tex, dstRect, srcRect, scale) function

Tile a texture repeatedly within the specified region. Optionally use a srcRect.

tex: The SDL_Texture to tile.

dstRect: The region to fill {x, y, w, h}.

srcRect: Optional portion of texture.

scale: A float scale factor for each tile.

Returns: None

get_image(rect) function

Read back the rendered pixels into a new SDL_Surface. If rect is undefined, capture entire output.

rect: Optional {x,y,w,h}.

Returns: An SDL_Surface with the requested region's pixels.

fasttext(text, pos, color) function

Draw debug text using an internal fast path. Typically used for quick debugging overlays.

text: The string to draw.

pos: The [x, y] position to draw text.

color: Optional [r,g,b,a].

Returns: None

geometry(texture, meshObject) function

Render custom geometry from a mesh object {pos, uv, color, indices, count} with an optional texture.

texture: The SDL_Texture or undefined.

meshObject: The geometry data with typed arrays.

Returns: None

scale(scaleVec2) function

Set a scaling factor for all subsequent rendering on this renderer.

scaleVec2: [sx, sy] scaling factors.

Returns: None

logical_size(size) function

Set a "logical" size that the renderer will scale to. For example, (320, 240) can auto-scale up to the window resolution.

size: [width, height].

Returns: None

viewport(rect) function

Set the clipping viewport for rendering. Pass undefined to use the full render target.

rect: {x, y, w, h}, or undefined.

Returns: None

clip(rect) function

Set or clear the clipping rectangle for drawing. Pass undefined to clear.

rect: {x, y, w, h} or undefined.

Returns: None

vsync(flag) function

Enable or disable vertical sync. This may have no effect depending on the driver.

flag: True or false.

Returns: None

coords(pos) function

Convert window coordinates to this renderer's coordinate space.

pos: [x, y] in window space.

Returns: [x, y] in renderer coordinate space.

camera(cameraTransform, centered) function

Set up a basic 2D camera matrix from a given transform. If 'centered' is true, the origin is the center of the viewport, else top-left.

cameraTransform: The transform whose pos is used.

centered: Boolean true or false.

Returns: None

get_viewport() function

Return the current viewport rect.

Returns: {x, y, w, h}

screen2world(pos) function

Convert a screen coordinate to world space based on the current camera transform.

pos: [x, y] screen coords

Returns: [wx, wy] in world space

target(texture) function

Set or clear the current render target texture. Pass undefined to reset to the default/window.

texture: An SDL_Texture or undefined

Returns: None

make_sprite_mesh(sprites) function

Generate a mesh from an array of sprite objects, combining their positions, UVs, and colors into a single geometry block.

sprites: An array of sprite-like objects.

Returns: A 'mesh' object with pos, uv, color, indices, etc.