Draw

:= []

Immediate-mode 2D drawing, text, textures, cameras, and render effects.

The host owns the outer frame scope and passes an opaque Frame capability to render!. Draw through that receiver so drawing cannot happen before BeginDrawing or after EndDrawing. Nested helpers keep raylib's begin/end state transitions paired. Create host-owned fonts, render textures, and shaders during initialization and keep them in the model; per-frame drawing and uniform updates do not allocate.

from_rgba : { r : U8, g : U8, b : U8, a : U8 } -> Color

Convert a structural RGBA value at an adapter boundary into roc-ray's color.

alpha_blend : BlendMode

Conventional source-alpha compositing.

additive_blend : BlendMode

Add source and destination colors, useful for light and glow effects.

filled : Color -> ShapeStyle

Create a fill-only shape style.

stroke : Color, F32 -> Stroke

Create a stroke with color and thickness in logical pixels.

default_font : Font

The built-in font, which requires no loading or host-owned resource.

align_offset : TextSize, TextAlign -> Vector2

Convert a measured size and alignment into an anchor offset.

origin_for : Vector2, TextSize, TextAlign -> Vector2

Find the top-left text origin for an anchored position.

align_factor : TextAlign -> Vector2

Convert text alignment into horizontal and vertical factors from 0 to 1.

center_in_rect : Rectangle, TextSize -> Vector2

Find the top-left position that centers measured text in a rectangle.

clear! : Frame, Color => {  }

Clear the active drawing target to a solid color.

circle_gradient! : Frame, CircleGradient => {  }

Draw a radial circle gradient.

fps! : Frame, Fps => {  }

Draw raylib's current frames-per-second counter.

rectangle! : Frame, Rectangle => {  }

Draw a filled and/or outlined axis-aligned rectangle.

rounded_rectangle! : Frame, RoundedRectangle => {  }

Draw a filled and/or outlined rounded rectangle.

circle! : Frame, Circle => {  }

Draw a filled and/or outlined circle.

line! : Frame, Line => {  }

Draw a stroked line segment. NoStroke performs no drawing.

triangle! : Frame, Triangle => {  }

Draw a filled and/or outlined triangle.

polygon! : Frame, Polygon => {  }

Compatibility alias for convex_polygon!.

convex_polygon! : Frame, ConvexPolygon => {  }

Draw a convex filled polygon and/or an ordered polygon outline. The host triangulates the fill without allocating; fewer than three points do not fill.

measure_text! : MeasureText => TextSize

Measure text without drawing it, using the selected font and spacing.

load_font! : LoadFont => Try(Font, [FontLoadFailed, ResourceLimit, ..])

Load a host-owned font from disk at the requested base size.

texture_draw : Texture -> TextureDraw

Create a draw configuration covering the whole texture at the origin.

texture_at : Texture, Vec2 -> TextureDraw

Create a draw configuration covering the whole texture at pos.

texture! : Frame, TextureDraw => {  }

Draw a texture with explicit source, destination, origin, rotation, and tint.

draw_texture! : Frame, TextureDraw => {  }

Compatibility alias for texture!.

projective_texture! : Frame, ProjectiveTexture => {  }

Project a texture onto a validated planar quad with exact homogeneous UV interpolation. This remains one hosted call and preserves active shaders.

projective_texture_view! : Frame, ProjectiveTextureView => {  }

Project a sampled texture view onto a validated planar quad.

load_render_texture! : RenderTextureSize => Try(RenderTexture, [RenderTextureLoadFailed, ResourceLimit, ..])

Allocate an offscreen framebuffer. Do this during initialization, not per frame; creation allocates GPU resources and one fixed host-heap slot.

render_texture : RenderTexture -> TextureView

View the color attachment as a sampled texture without allocating or copying. The returned reference keeps the owning framebuffer alive.

render_texture_source : RenderTexture -> Rect

Render textures use OpenGL framebuffer coordinates, so their color attachment is vertically inverted when sampled on screen.

load_shader! : LoadShader => Try(Shader, [ShaderLoadFailed, ResourceLimit, ..])

Load shader stages from files. Pass an empty string to use raylib's default vertex or fragment stage.

load_shader_source! : LoadShaderSource => Try(Shader, [ShaderLoadFailed, ResourceLimit, ..])

Compile shader stages from source strings. Empty strings select the default stage, which is useful for fragment-only 2D post-processing.

with_render_texture! : Frame, RenderTexture, (Frame => Try(result, [ScopeLimit, ScopeUnavailable, ..errors])) => Try(result, [ScopeLimit, ScopeUnavailable, ..errors])

Scope offscreen rendering so BeginTextureMode/EndTextureMode stay paired. Callback errors are returned only after the native target has been restored.

with_shader! : Frame, Shader, (Frame => Try(result, [ScopeLimit, ScopeUnavailable, ..errors])) => Try(result, [ScopeLimit, ScopeUnavailable, ..errors])

Scope shader application so the default shader is always restored. Callback errors are returned only after the previous shader has been restored.

with_blend_mode! : Frame, BlendMode, (Frame => Try(result, [ScopeLimit, ..errors])) => Try(result, [ScopeLimit, ..errors])

Scope one of raylib's built-in blend equations. Custom blend factors are deliberately excluded until they can be represented without global state.

with_camera! : Frame, CameraMode, (Frame => Try(result, [ScopeLimit, ..errors])) => Try(result, [ScopeLimit, ..errors])

Draw the callback in world space using this camera.

with_mode_2d! : Frame, CameraMode, (Frame => Try(result, [ScopeLimit, ..errors])) => Try(result, [ScopeLimit, ..errors])

Compatibility alias for with_camera!.

with_scissor! : Frame, Rect, (Frame => Try(result, [ScopeLimit, ..errors])) => Try(result, [ScopeLimit, ..errors])

Restrict callback drawing to screen-space bounds, then always close the scissor before returning. Use this instead of manually pairing the raw effects.

text! : Frame, Text => {  }

Draw text using explicit font, spacing, color, and anchor alignment.

debug_text! : Frame, DebugText => {  }

Draw top-left aligned text with the built-in font and default spacing.

text_at! : Frame, SimpleText => {  }

Draw simple top-left aligned text with the built-in font.

text_centered! : Frame, SimpleText => {  }

Draw simple text centered on its position.

Frame

Draw.Frame :: # (opaque)

Opaque, zero-sized authority supplied only while the host is running render!. It prevents drawing during initialization, but Roc does not yet enforce affine use or encode a frame epoch; do not retain it in the model.

Vector2 : Vec2

Two-dimensional vector used by drawing records.

Rect : Rect

Axis-aligned rectangle used by drawing records.

Fill : [NoFill, Fill(Color)]

Optional shape fill.

Stroke : [NoStroke, Stroke({ color : Color, thickness : F32 })]

Optional shape outline with color and thickness.

ShapeStyle : {
    fill : Fill,
    stroke : Stroke,
}

Combined fill and outline applied by shape helpers.

Rectangle : {
    x : F32,
    y : F32,
    width : F32,
    height : F32,
    style : ShapeStyle,
}

Axis-aligned rectangle and its style.

RoundedRectangle : {
    x : F32,
    y : F32,
    width : F32,
    height : F32,
    radius : F32,
    segments : I32,
    style : ShapeStyle,
}

Rounded rectangle; radius and segment count control corner tessellation.

Circle : {
    center : Vector2,
    radius : F32,
    style : ShapeStyle,
}

Circle and its style.

CircleGradient : {
    center : Vector2,
    radius : F32,
    color_inner : Color,
    color_outer : Color,
}

Radial gradient from inner to outer color.

Line : {
    start : Vector2,
    end : Vector2,
    stroke : Stroke,
}

Line segment and stroke.

Triangle : {
    a : Vector2,
    b : Vector2,
    c : Vector2,
    style : ShapeStyle,
}

Triangle vertices and style.

ConvexPolygon : {
    points : List(Vector2),
    style : ShapeStyle,
}

A simple convex polygon. Points must be ordered around the boundary (clockwise or counter-clockwise). Filled concave or self-intersecting polygons are not supported; outlines accept any ordered point path.

Polygon : ConvexPolygon

Compatibility alias for ConvexPolygon. Prefer ConvexPolygon and convex_polygon! in new code so the fill constraint is visible at call sites.

Fps : {
    pos : Vector2,
    size : F32,
    color : Color,
}

Position, size, and color for the FPS counter.

Font : Font

The built-in font is allocation-free. A loaded font is an opaque host-owned resource whose final reference unloads its texture automatically.

HAlign : [Left, Center, Right]

Horizontal text anchor.

VAlign : [Top, Middle, Bottom]

Vertical text anchor.

TextAlign : {
    horizontal : HAlign,
    vertical : VAlign,
}

Horizontal and vertical text anchor.

TextSize : {
    width : F32,
    height : F32,
}

Measured text dimensions in logical pixels.

Text : {
    pos : Vector2,
    text : Str,
    size : F32,
    spacing : F32,
    color : Color,
    font : Font,
    align : TextAlign,
}

Fully configured text draw.

DebugText : {
    pos : Vector2,
    text : Str,
    size : F32,
    color : Color,
}

Built-in-font text intended for quick diagnostics.

SimpleText : {
    pos : Vector2,
    text : Str,
    size : F32,
    color : Color,
}

Built-in-font text with default spacing.

MeasureText : {
    text : Str,
    size : F32,
    spacing : F32,
    font : Font,
}

Text measurement configuration.

LoadFont : {
    path : Str,
    size : I32,
}

Font path and base pixel size.

TextureDraw : TextureDrawConfig

Resolved texture draw configuration.

ProjectiveQuad

Draw.ProjectiveQuad :: # (opaque)

A finite, convex planar projection with a bounded homography. Construct it with ProjectiveQuad.from_corners; the opaque representation carries the homogeneous weights needed for exact perspective-correct interpolation.

from_corners : ProjectiveQuadCorners -> Try(ProjectiveQuad, [NonFiniteQuad, DegenerateQuad, NonConvexQuad, ProjectiveHorizon, ..])

Validate four boundary-ordered corners and solve their projective weights. A single homography cannot represent a concave, self-intersecting, or horizon-crossing destination, so those states are rejected here.

project : ProjectiveQuad, Vec2 -> Vec2

Project a unit-square coordinate onto the destination surface. This uses the same homography as rendering and is useful for aligned overlays.

ProjectiveTexture : {
    texture : Texture,
    source : Rect,
    quad : ProjectiveQuad,
    tint : Color,
}

Texture and source region projected exactly onto a validated planar quad.

CameraMode : Camera2D

Camera accepted by scoped 2D drawing.

RenderTexture

Draw.RenderTexture :: # (opaque)

Host-owned framebuffer. Its texture-shaped box has a distinct host kind; the host rejects ordinary textures before entering an offscreen scope. Releasing the final reference unloads the framebuffer and both attachments.

load! : RenderTextureSize => Try(RenderTexture, [RenderTextureLoadFailed, ResourceLimit, ..])

Allocate an offscreen framebuffer.

texture : RenderTexture -> TextureView

Read-only view of this render target's color attachment.

source : RenderTexture -> Rect

Vertically inverted full-source rectangle for drawing the color attachment.

Shader

Draw.Shader :: # (opaque)

Host-owned GPU shader. Empty vertex/fragment strings select raylib's default stage. Keep this value alive for every cached Uniform derived from it.

load! : LoadShader => Try(Shader, [ShaderLoadFailed, ResourceLimit, ..])

Load shader stages from files.

from_source! : LoadShaderSource => Try(Shader, [ShaderLoadFailed, ResourceLimit, ..])

Compile shader stages from source strings.

uniform_f32! : Shader, Str => Try(F32Uniform, [UniformNotFound, ..])

Resolve a scalar floating-point uniform once.

uniform_i32! : Shader, Str => Try(I32Uniform, [UniformNotFound, ..])

Resolve a scalar integer uniform once.

uniform_vec2! : Shader, Str => Try(Vec2Uniform, [UniformNotFound, ..])

Resolve a two-component vector uniform once.

uniform_vec3! : Shader, Str => Try(Vec3Uniform, [UniformNotFound, ..])

Resolve a three-component vector uniform once.

uniform_vec4! : Shader, Str => Try(Vec4Uniform, [UniformNotFound, ..])

Resolve a four-component vector uniform once.

uniform_color! : Shader, Str => Try(ColorUniform, [UniformNotFound, ..])

Resolve a color-valued vec4 uniform once.

uniform_texture! : Shader, Str => Try(TextureUniform, [UniformNotFound, ..])

Resolve a sampled-texture uniform once.

LoadShader : {
    vertex_path : Str,
    fragment_path : Str,
}

File paths for shader stages. An empty path selects the default stage.

LoadShaderSource : {
    vertex_source : Str,
    fragment_source : Str,
}

Shader source strings. An empty string selects the default stage.

F32Uniform

Draw.F32Uniform :: # (opaque)

Typed uniform handles are zero-cost nominal wrappers over the cached host location plus its owning shader. Their distinct types prevent using the wrong setter without adding a tag, allocation, or host lookup.

Vec2Uniform

Draw.Vec2Uniform :: # (opaque)
set! : Vec2Uniform, Vector2 => {  }

Vec3Uniform

Draw.Vec3Uniform :: # (opaque)
set! : Vec3Uniform, Vec3 => {  }

Vec4Uniform

Draw.Vec4Uniform :: # (opaque)
set! : Vec4Uniform, Vec4 => {  }

TextureUniform

Draw.TextureUniform :: # (opaque)
set! : TextureUniform, TextureView => {  }

Bind any sampled texture view, including a render-target attachment.

set_texture! : TextureUniform, Texture => {  }

Convenience setter for an ordinary mutable texture.

Vec3 : { x : F32, y : F32, z : F32 }

Three-component shader uniform value.

Vec4 : { x : F32, y : F32, z : F32, w : F32 }

Four-component shader uniform value.

BlendMode : [
    Alpha,
    Additive,
    Multiplied,
    AddColors,
    SubtractColors,
    AlphaPremultiply,
]

Built-in blend equations with scoped application through with_blend_mode!.

ScopeError : [ScopeLimit, ScopeUnavailable]

A scoped renderer could not be opened because its bounded native stack is full or a transferred host resource no longer resolves.