Render API
📐 Constants
const uint8 RR_TOP_LEFT
const uint8 RR_TOP_RIGHT
const uint8 RR_BOTTOM_LEFT
const uint8 RR_BOTTOM_RIGHTRectangle-corner rounding flags (bitmask).
const int TE_NONE
const int TE_OUTLINE
const int TE_SHADOW
const int TE_GLOWText 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; set0to 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 ofTE_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.dynamic—truefor per-frame updates (typical),falsefor 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 fromcreate_shader.vb— Required. Handle fromcreate_vertex_buffer.vertex_data— Raw vertex bytes packed intoarray<uint8>. Must match the shader's layout stride.vertex_count— Number of vertices to draw.topology— One of theTOPO_*constants.blend— Blend state handle, or0for default blending.sampler— Sampler handle, or0for no sampler.texture— Texture handle, or0for no texture.tex_slot— Texture/sampler register slot (usually0).cb— Constant buffer handle, or0for no constants.cb_data— Raw constant data asarray<uint8>, ornullif no constants.cb_slot— Constant buffer register slot (usually0).
Custom draw commands respect draw order with all other render functions. If you call
draw_rect_filled, thencustom_draw, thendraw_text, they render in exactly that order.
Render Target Control
custom_set_render_target— Redirects subsequentcustom_drawcalls 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_32bit—truefor 32-bit indices (uint),falsefor 16-bit (uint16). Use 32-bit for meshes with more than 65535 vertices.dynamic—truefor per-frame updates,falsefor 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 theCMP_*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— Typicallytrue. 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 beforedraw_meshorcustom_drawto 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. Pass0for 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 forfloat4).element_count— Number of elements.cpu_write—trueto allow CPU updates viaupdate_structured_buffer. Creates SRV only.gpu_write—trueto allow GPU writes from compute shaders. Creates both SRV and UAV.bind_structured_buffer— Binds the buffer to a shader stage. CS stage withgpu_writebinds as UAV, otherwise SRV. UseSTAGE_VS,STAGE_PS, orSTAGE_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 ascreate_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. Pass0, 0to 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. Pass0for depth buffer to use color-only (same behavior ascustom_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