Render API

📐 Constants

const uint8 RR_TOP_LEFT
const uint8 RR_TOP_RIGHT
const uint8 RR_BOTTOM_LEFT
const uint8 RR_BOTTOM_RIGHT

Rectangle-corner rounding flags (bitmask).

const int TE_NONE
const int TE_OUTLINE
const int TE_SHADOW
const int TE_GLOW

Text rendering effects.


🎨 Viewport

void get_view(float &out w, float &out h)
float get_view_scale()
double get_fps()
  • get_view — Returns the current viewport width/height in pixels.

  • get_view_scale — Returns the viewport reference scale (for DPI scaling, etc).

  • get_fps() — Returns current frames per second.


📏 Basic Shapes

Rectangle

Draws an outlined rectangle.

Filled Rectangle

Draws a filled rectangle.

Line

Draws a line between (x1,y1) and (x2,y2).

Arc

Draws an arc or pie-slice centered at (cx, cy).

Circle

Triangle

Polygon

  • xy_pairs[x0, y0, x1, y1, …]

  • count_pairs — optional; set 0 to use full array length.

Four Corner Gradient

Draws a gradient rectangle with individual RGBA colors for each corner.


🖼️ Bitmaps

  • create_bitmap — Creates a bitmap from raw RGBA or compressed bytes. Returns an encrypted handle (uint64) used for drawing.

  • draw_bitmap — Draws the bitmap tinted with color (r,g,b,a).


🔤 Fonts & Text

Text Drawing

  • effect — One of TE_NONE, TE_OUTLINE, TE_SHADOW, TE_GLOW.

  • effect_color(er,eg,eb,ea).

  • effect_amount — Intensity scalar.

Text Metrics

Measure text dimensions or a single character's advance width.


✂️ Clipping


Example


🔺 Custom Draw (Shaders & Direct GPU Access)

The custom draw API gives scripts direct access to the D3D11 GPU pipeline — custom HLSL shaders, vertex buffers, textures, render targets, and all primitive topologies. Custom draw commands respect draw order with all other render functions.

Constants

Topology

Blend Factors

Blend Operations

Vertex Layout Element Types

Texture Filter Modes

Texture Address Modes

Shaders

Creates a compiled shader from HLSL source strings. The layout parameter is a format string describing the vertex input layout:

Format: SEMANTIC:semantic_index:TYPE separated by commas. Supported types: FLOAT1, FLOAT2, FLOAT3, FLOAT4, BYTE4, UINT1.

Returns 0 on compilation failure. Shader entry point must be main for both VS and PS.

Vertex Buffers

  • stride — Bytes per vertex (must match shader layout).

  • max_vertices — Maximum number of vertices the buffer can hold.

  • dynamictrue for per-frame updates (typical), false for static geometry.

Constant Buffers

Size is automatically aligned to 16 bytes. Bound to both VS and PS at the specified slot.

Blend States

For premultiplied alpha (recommended for overlay rendering):

For standard alpha blending:

Samplers

Controls how textures are sampled. FILTER_LINEAR for smooth scaling, FILTER_POINT for pixel-perfect rendering.

Textures

Creates a texture from raw RGBA pixel data. The rgba_data array must be exactly width * height * 4 bytes.

Render Targets

Creates an offscreen render target for multi-pass rendering. Pass 0 for width/height to match the viewport size.

Drawing

The main draw call. Submits custom geometry to the GPU using the specified shader and resources.

  • shader — Required. Handle from create_shader.

  • vb — Required. Handle from create_vertex_buffer.

  • vertex_data — Raw vertex bytes packed into array<uint8>. Must match the shader's layout stride.

  • vertex_count — Number of vertices to draw.

  • topology — One of the TOPO_* constants.

  • blend — Blend state handle, or 0 for default blending.

  • sampler — Sampler handle, or 0 for no sampler.

  • texture — Texture handle, or 0 for no texture.

  • tex_slot — Texture/sampler register slot (usually 0).

  • cb — Constant buffer handle, or 0 for no constants.

  • cb_data — Raw constant data as array<uint8>, or null if no constants.

  • cb_slot — Constant buffer register slot (usually 0).

Custom draw commands respect draw order with all other render functions. If you call draw_rect_filled, then custom_draw, then draw_text, they render in exactly that order.

Render Target Control

  • custom_set_render_target — Redirects subsequent custom_draw calls to an offscreen render target.

  • custom_reset_render_target — Switches back to the main backbuffer.

  • custom_bind_rt_as_texture — Binds a render target's contents as a texture for sampling in a shader.

  • custom_restore_state — Resets the D3D11 pipeline state. Call after render target operations to ensure normal rendering continues correctly.

Packing Vertex Data

Since custom_draw takes raw bytes, you need to pack floats into array<uint8>. Use fpToIEEE to convert floats:

Resource Cleanup

All custom draw resources are automatically destroyed when a script is unloaded. You can also destroy them manually:


🔢 Index Buffers & Indexed Drawing

  • max_indices — Maximum number of indices the buffer can hold.

  • use_32bittrue for 32-bit indices (uint), false for 16-bit (uint16). Use 32-bit for meshes with more than 65535 vertices.

  • dynamictrue for per-frame updates, false for static geometry.

Same as custom_draw but uses an index buffer to avoid duplicating shared vertices. Useful for cubes, grids, and any geometry with shared edges.


🧊 Depth/Stencil State

Depth Comparison Constants

  • depth_enable — Enable depth testing.

  • depth_write — Write to depth buffer on pass.

  • compare_func — One of the CMP_* constants.

  • custom_set_depth_stencil_state(0) — Resets to default (no depth testing).

For solid 3D rendering, use create_depth_stencil_state(true, true, CMP_LESS).


🔳 Rasterizer State

Cull/Fill Constants

  • scissor_enable — Typically true. Required for clipping to work.

  • custom_set_rasterizer_state(0) — Resets to default.

For 3D meshes where you want to see all faces (pyramids, etc), use CULL_NONE.


📺 Viewport & Texture Binding

  • custom_set_viewport — Restricts rendering to a sub-region of the screen. Use before draw_mesh or custom_draw to confine 3D rendering to a panel.

  • custom_reset_viewport — Restores the full viewport.

  • custom_bind_texture — Binds a texture + sampler to a slot, persisting across subsequent draw calls. Pass 0 for texture to bind the backbuffer capture result.


💻 Compute Shaders

Creates and dispatches a compute shader (cs_5_0). Entry point must be main. Thread group counts (x, y, z) are passed to Dispatch().

Compute shaders are dispatched as state-only commands — no geometry is drawn. Use structured buffers for CS input/output.

Bind Stage Constants


📊 Structured Buffers

  • element_size — Size of each element in bytes (typically 16 for float4).

  • element_count — Number of elements.

  • cpu_writetrue to allow CPU updates via update_structured_buffer. Creates SRV only.

  • gpu_writetrue to allow GPU writes from compute shaders. Creates both SRV and UAV.

  • bind_structured_buffer — Binds the buffer to a shader stage. CS stage with gpu_write binds as UAV, otherwise SRV. Use STAGE_VS, STAGE_PS, or STAGE_CS.

Example: GPU particle buffer


📷 Backbuffer Capture

Captures the current backbuffer contents to a staging texture and binds it as a shader resource at the specified slot. Use with a custom pixel shader to create post-processing effects like bloom, blur, color grading, or screen-space reflections.


🖼️ Texture Loading

  • load_texture_mem — Decodes PNG, JPG, BMP, TGA, or GIF from a byte array. Returns a texture handle (same type as create_texture).

  • load_texture — Loads an image file from disk. Tries the script directory first, then the absolute path.

  • get_texture_info — Returns the texture dimensions.

  • Destroy with destroy_texture(handle).


🏔️ Mesh Loading (OBJ)

Parses Wavefront OBJ format with support for positions (v), normals (vn), texture coordinates (vt), faces with 3+ vertices (auto-triangulated), and negative indices.

Fixed vertex layout: POSITION:0:FLOAT3, NORMAL:0:FLOAT3, TEXCOORD:0:FLOAT2 — 32 bytes per vertex. Shaders used with loaded meshes must match this layout.

  • get_mesh_info — Returns vertex/index counts and the axis-aligned bounding box.

  • load_mesh — Loads from disk, tries script directory first.


🔺 Drawing Meshes

Convenience draw call for loaded or procedural meshes. Binds the mesh's internal vertex/index buffers and calls DrawIndexed in one step. Pass 0 for optional handles (sampler, texture, cb). The shader layout must match the mesh's vertex format.

Example: render a lit OBJ mesh


🌊 Depth Buffers & 3D Rendering

  • create_depth_buffer — Creates a D24S8 depth/stencil buffer. Pass 0, 0 to match viewport size.

  • custom_set_render_target_ext — Binds a render target with an optional depth buffer for proper 3D occlusion. Auto-clears both, sets viewport and scissor to RT dimensions. Pass 0 for depth buffer to use color-only (same behavior as custom_set_render_target).

  • custom_clear_render_target — Clears a render target to a specific color without re-binding it.

  • custom_clear_depth_buffer — Clears depth to 1.0 and stencil to 0.

Example: solid 3D scene with depth


🎛️ Multi-CB Binding

Binds a constant buffer to a specific register slot and shader stage, independently of draw calls. This persists across subsequent draws until changed. Use STAGE_VS, STAGE_PS, or STAGE_CS.

This enables multi-buffer shader setups where camera data lives on b0, material properties on b1, and lighting on b2:

Note: when using custom_bind_constant_buffer for the MVP, pass 0 for the cb parameter of draw_mesh to avoid it overwriting your manually bound buffers.


🧱 Procedural Mesh

  • create_mesh_raw — Builds a mesh from raw vertex and index byte arrays with any vertex layout. The shader must match the stride. Use for procedural terrain, generated geometry, or particle quads.

  • get_mesh_stride — Returns the vertex stride in bytes (32 for OBJ-loaded meshes).

  • Destroy with destroy_mesh(handle).

The vertex data can use any layout — it's not restricted to the OBJ format's position+normal+uv.


🎨 Dynamic Texture Update

Performs a partial update of an existing texture. The rgba_data must be exactly w * h * 4 bytes. Use for dynamic sprite sheets, minimaps, procedural atlases, or any per-frame texture content.


🌌 Example: Nebula Shader


🧪 Example: Full API Test


🧪 Example: Full API Test 2 — Advanced (3D, Compute, Mesh Loading)

Last updated