logo
Expand description

šŸ–¼ļø Render API

Immediate mode rendering API for drawing 2D and 3D meshes on screen.

Unlike the World API, which has persistent entities, in the Render API you list everything that should be drawn every frame, hence immediate mode.

The Render API supports the creation of textures through a TextureBuilder. Textures are created from image data and can be ā€œwrapped aroundā€ surfaces to add another level of artistic control to your game.

Examples

Given a valid texture named texture created with the TextureBuilder, you can draw a textured 2D square in screen space like so:

use ark_api::render::{Rectangle};
use ark_api::{Vec2, ColorRgba8};

// We draw two triangles, reusing some of the vertices:
let indices = [
    [0, 1, 2], // first triangle
    [1, 2, 3], // second triangle
];

// We can specify a region to which to clip our triangles.
// In this case, we don't want to clip.
let clip_rect = Rectangle {
    min_x: 0.0,
    min_y: 0.0,
    max_x: 1_000_000.0,
    max_y: 1_000_000.0,
};

// Render API expects positions in physical pixel coordinates,
// so we multiply our local coordinates with dpi_factor:
let dpi_factor = applet().window_state().dpi_factor;

let positions = [
    dpi_factor * Vec2::new(50.0, 50.0),   // 0
    dpi_factor * Vec2::new(50.0, 300.0),  // 1
    dpi_factor * Vec2::new(300.0, 50.0),  // 2
    dpi_factor * Vec2::new(300.0, 300.0), // 3
];
let colors = [
    ColorRgba8([255, 0, 0, 255]),     // 0
    ColorRgba8([0, 255, 0, 255]),     // 1
    ColorRgba8([0, 0, 255, 255]),     // 2
    ColorRgba8([255, 255, 255, 255]), // 3
];

let uvs = [
    Vec2::new(0.0, 0.0), // 0
    Vec2::new(0.0, 1.0), // 1
    Vec2::new(1.0, 0.0), // 2
    Vec2::new(1.0, 1.0), // 3
];

render().draw_textured_triangles(&clip_rect, &texture, &indices, &positions, &colors, &uvs)?;

Structs

Describes the transform of a bone. More compact and more defined than a Mat4.

Stable instance ID for identifying an instance over frame.

Colored 3D line

Used to restrict the drawing of 2d triangles to a specific region.

Gives access to rendering specific functionality like drawing 2D triangles.

Create RenderMaterial through builder pattern

A handle to a mesh.

Flags to specify attributes about mesh data when creating meshes.

Creates RenderMeshInstance through the builder pattern

Section of a mesh.

Adjusts the style of drawn meshes.

Create RenderMeshStyle through builder pattern

Specified an SDF instance to be rendered.

An Sdf (signed distance field) that can be rendered directly.

Immutable texture object stored in GPU memory.

Builder for creating textures.

Enums

Describes how a texture stores its data.

Functions

Converts an IsoTransform to a BoneTransform. Lossless.

Type Definitions

Handle to a texture in Ark.