On this page:
9.1 Basic Rendering
render-clear!
render-present!
9.2 Colors
set-draw-color!
get-draw-color
set-draw-color-float!
get-draw-color-float
color->SDL_  Color
9.3 Blend Modes
set-blend-mode!
get-blend-mode
symbol->blend-mode
blend-mode->symbol
9.4 Drawing Shapes
9.4.1 Points
draw-point!
draw-points!
9.4.2 Lines
draw-line!
draw-lines!
9.4.3 Rectangles
draw-rect!
fill-rect!
draw-rects!
fill-rects!
9.5 Geometry Rendering
make-vertex
render-geometry!
9.6 Debug Text
render-debug-text!
debug-text-font-size
9.7 Viewport and Clipping
set-render-viewport!
get-render-viewport
set-render-clip-rect!
get-render-clip-rect
render-clip-enabled?
set-render-scale!
get-render-scale
9.8 Renderer Information
renderer-name
render-output-size
current-render-output-size
num-render-drivers
render-driver-name
9.9 VSync
set-render-vsync!
get-render-vsync
9.0.0.11

9 Drawing🔗ℹ

This section covers 2D drawing operations: colors, shapes, and rendering.

9.1 Basic Rendering🔗ℹ

procedure

(render-clear! ren)  void?

  ren : renderer?
Clears the entire rendering target with the current draw color. Call this at the start of each frame before drawing.

procedure

(render-present! ren)  void?

  ren : renderer?
Displays the rendered content to the screen. Call this at the end of each frame after all drawing is complete.

The basic rendering pattern is:

;; Each frame:
(set-draw-color! ren 0 0 0)   ; Black background
(render-clear! ren)
;; ... draw shapes, textures, text ...
(render-present! ren)

9.2 Colors🔗ℹ

procedure

(set-draw-color! ren r g b [a])  void?

  ren : renderer?
  r : (integer-in 0 255)
  g : (integer-in 0 255)
  b : (integer-in 0 255)
  a : (integer-in 0 255) = 255
Sets the color used for drawing operations. Color components are integers from 0 to 255.

  • r Red component

  • g Green component

  • b Blue component

  • a Alpha (opacity), 255 = fully opaque (default)

(set-draw-color! ren 255 0 0)       ; Red
(set-draw-color! ren 0 255 0 128)   ; Semi-transparent green

procedure

(get-draw-color ren)  
(integer-in 0 255)
(integer-in 0 255)
(integer-in 0 255)
(integer-in 0 255)
  ren : renderer?
Returns the current draw color as four values: r, g, b, a.

procedure

(set-draw-color-float! ren r g b [a])  void?

  ren : renderer?
  r : real?
  g : real?
  b : real?
  a : real? = 1.0
Sets the draw color using floating-point values. Standard range is 0.0 to 1.0, but values can exceed 1.0 for HDR rendering.

procedure

(get-draw-color-float ren)  
real? real? real? real?
  ren : renderer?
Returns the current draw color as four floating-point values.

procedure

(color->SDL_Color color)  any/c

  color : (or/c list? vector?)
Converts a color specification to an SDL_Color struct. Accepts:
  • A list '(r g b) or '(r g b a)

  • A vector #(r g b) or #(r g b a)

If alpha is omitted, it defaults to 255.

9.3 Blend Modes🔗ℹ

procedure

(set-blend-mode! ren mode)  void?

  ren : renderer?
  mode : (or/c 'none 'blend 'add 'mod 'mul symbol?)
Sets the blend mode for drawing operations.

  • 'none No blending, overwrites destination

  • 'blend (or 'alpha) — Standard alpha blending

  • 'add (or 'additive) — Additive blending (good for glow effects)

  • 'mod (or 'modulate) — Color modulation

  • 'mul (or 'multiply) — Multiply blending

procedure

(get-blend-mode ren)

  (or/c 'none 'blend 'add 'mod 'mul symbol?)
  ren : renderer?
Returns the current blend mode as a symbol.

procedure

(symbol->blend-mode sym)  exact-integer?

  sym : symbol?
Converts a blend mode symbol to its SDL constant value.

procedure

(blend-mode->symbol mode)  symbol?

  mode : exact-integer?
Converts an SDL blend mode constant to a symbol.

9.4 Drawing Shapes🔗ℹ

All shape-drawing functions use the current draw color set by set-draw-color!. Coordinates can be integers or floats.

9.4.1 Points🔗ℹ

procedure

(draw-point! ren x y)  void?

  ren : renderer?
  x : real?
  y : real?
Draws a single point at the given coordinates.

procedure

(draw-points! ren points)  void?

  ren : renderer?
  points : 
(listof (or/c (list/c real? real?)
              (vector/c real? real?)))
Draws multiple points. Each point can be a list '(x y) or vector #(x y).

(draw-points! ren '((100 100) (150 120) (200 100)))

9.4.2 Lines🔗ℹ

procedure

(draw-line! ren x1 y1 x2 y2)  void?

  ren : renderer?
  x1 : real?
  y1 : real?
  x2 : real?
  y2 : real?
Draws a line from (x1, y1) to (x2, y2).

procedure

(draw-lines! ren points)  void?

  ren : renderer?
  points : 
(listof (or/c (list/c real? real?)
              (vector/c real? real?)))
Draws connected line segments through a list of points.

;; Draw a triangle outline
(draw-lines! ren '((100 200) (200 100) (300 200) (100 200)))

9.4.3 Rectangles🔗ℹ

procedure

(draw-rect! ren x y w h)  void?

  ren : renderer?
  x : real?
  y : real?
  w : real?
  h : real?
Draws a rectangle outline.

procedure

(fill-rect! ren x y w h)  void?

  ren : renderer?
  x : real?
  y : real?
  w : real?
  h : real?
Draws a filled rectangle.

(set-draw-color! ren 255 0 0)
(fill-rect! ren 100 100 200 150)  ; Red filled rectangle

procedure

(draw-rects! ren rects)  void?

  ren : renderer?
  rects : 
(listof (or/c (list/c real? real? real? real?)
              (vector/c real? real? real? real?)))
Draws multiple rectangle outlines. Each rect is '(x y w h) or #(x y w h).

procedure

(fill-rects! ren rects)  void?

  ren : renderer?
  rects : 
(listof (or/c (list/c real? real? real? real?)
              (vector/c real? real? real? real?)))
Draws multiple filled rectangles.

9.5 Geometry Rendering🔗ℹ

For complex shapes, use vertex-based geometry rendering.

procedure

(make-vertex x y r g b [a #:uv uv])  any/c

  x : real?
  y : real?
  r : real?
  g : real?
  b : real?
  a : real? = 1.0
  uv : (or/c (cons/c real? real?) #f) = #f
Creates a vertex for geometry rendering.

  • x, y Position coordinates

  • r, g, b, a Color (0.0 to 1.0)

  • uv Optional texture coordinates as (cons u v)

procedure

(render-geometry! ren    
  vertices    
  [#:indices indices    
  #:texture tex])  void?
  ren : renderer?
  vertices : (listof any/c)
  indices : (or/c (listof exact-nonnegative-integer?) #f) = #f
  tex : (or/c any/c #f) = #f
Renders triangles using vertex data.

  • vertices List of vertices from make-vertex

  • indices Optional index list for indexed rendering

  • tex Optional texture for textured triangles

Vertices are rendered as triangles (every 3 vertices form a triangle).

;; Draw a colored triangle
(render-geometry! ren
  (list (make-vertex 400 100 1.0 0.0 0.0)   ; Top (red)
        (make-vertex 200 400 0.0 1.0 0.0)   ; Bottom-left (green)
        (make-vertex 600 400 0.0 0.0 1.0))) ; Bottom-right (blue)

9.6 Debug Text🔗ℹ

procedure

(render-debug-text! ren x y text)  void?

  ren : renderer?
  x : real?
  y : real?
  text : string?
Renders text using SDL’s built-in 8x8 bitmap font. Useful for debugging, FPS counters, and quick UI without loading a TTF font.

The text color is controlled by set-draw-color!.

(set-draw-color! ren 255 255 255)
(render-debug-text! ren 10 10 "FPS: 60")

The size of the debug text font (8 pixels per character).

9.7 Viewport and Clipping🔗ℹ

procedure

(set-render-viewport! ren rect)  void?

  ren : renderer?
  rect : (or/c any/c #f)
Sets the viewport for rendering. The viewport defines which portion of the render target is used for drawing. Pass #f to use the entire target.

procedure

(get-render-viewport ren)  any/c

  ren : renderer?
Returns the current viewport as an SDL_Rect.

procedure

(set-render-clip-rect! ren rect)  void?

  ren : renderer?
  rect : (or/c any/c #f)
Sets a clipping rectangle. Drawing outside this rectangle is clipped. Pass #f to disable clipping.

procedure

(get-render-clip-rect ren)  any/c

  ren : renderer?
Returns the current clipping rectangle.

procedure

(render-clip-enabled? ren)  boolean?

  ren : renderer?
Returns #t if clipping is currently enabled.

procedure

(set-render-scale! ren scale-x scale-y)  void?

  ren : renderer?
  scale-x : real?
  scale-y : real?
Sets the render scale. All drawing coordinates are multiplied by these factors. Useful for resolution-independent rendering.

procedure

(get-render-scale ren)  
real? real?
  ren : renderer?
Returns the current render scale as two values.

9.8 Renderer Information🔗ℹ

procedure

(renderer-name ren)  string?

  ren : renderer?
Returns the name of the rendering backend (e.g., "metal", "opengl").

Returns the renderer’s output size in pixels as two values: width and height.

Returns the current output size, considering render target and logical size.

Returns the number of available render drivers.

procedure

(render-driver-name index)  string?

  index : exact-nonnegative-integer?
Returns the name of the render driver at the given index.

9.9 VSync🔗ℹ

procedure

(set-render-vsync! ren vsync)  void?

  ren : renderer?
  vsync : exact-integer?
Sets the VSync mode for the renderer.

  • 0 VSync off

  • 1 VSync on

  • -1 Adaptive VSync (if supported)

procedure

(get-render-vsync ren)  exact-integer?

  ren : renderer?
Returns the current VSync setting.