Crate rin[][src]



In order to use rin you’ll need to install rust first:

Once installed you can install rin’s extension to cargo running:

cargo install cargo-rin

To update to a new version later you can run:

cargo install --force cargo-rin

You can now create new rin projects by running from a console:

cargo rin new project_path

Which will create a default empty project. For more options run

cargo rin --help

Basic example

In order to create a basic example we need to pass the --no-ecs parameter to the cargo rin tool:

cargo rin new --no-ecs basic_example

After creating a new project you’ll end up with something that should look like:

struct App{


impl App{
    pub fn new(gl: &gl::Renderer, window: &mut window::Window) -> App{

impl ApplicationCallbacks for App{
    fn update(&mut self, delta: f64, gl: &gl::Renderer, window: &mut window::Window){


    fn draw(&mut self, gl: &gl::Renderer, window: &window::Window){
        let gl = gl.with(Mvp::ortho_top_left(window.viewport()));


    fn key_pressed(&mut self, key: window::Key, mods: window::KeyModifiers, repeat: bool){


If you’ve used other creative frameworks the above should result familiar with some differences mostly comming from rust’s own syntax.

The most important parts in this template are:


Scene template

The main way to use rin is through it’s scene module which provides an ECS (Entity Component System) or data driven programming framework which works in a very different way to the examples above. Working with the scene module implies a more declarative style in which the data we create is managed by the system for a lot of basic tasks like rendering.

For example using the non ECS approach, to draw a geometry we usually create a mesh, a material and then in the draw function we explicitly call draw on it. We might even put that mesh on a vao in GPU memory to optimize drawing.

When using the scene module we first create a scene object and through that scene create a model with a geometry and material. Also using the scene we would create a light and a camera. From there on the system will draw that object without any explicit draw call. The scene holds those components and we don’t usually care about the details of how they are drawn to the screen. Since the scene handles all the objects, that gives it a much better opportunity for optimization.

In general when working with bigger applications particularly with 3D worlds it’s highly recommended to use the scene module rather than trying than an imperative method and indeed the most advanced 3D features like PBR materials, lights or shadows are only supported when using a scene. Apart from performance reasons, Rust ownership model makes it easier to work with the ECS architecture that the scene module uses, than using object oriented programming when there’s many objects that would interact with each other in a traditional OO application.

Using the cargo rin tool we can create an application to use the ECS template:

cargo rin new scene_example

This is an example of the setup functions of a rin application that creates hundreds of spheres reusing the geometry and material through the scene module:

use rin::color::consts::*;
use rin::graphics::{sphere_coords, Node, arcball_camera};
use rin::scene::Scene;
use rin::material::StandardMaterialBuilder;

fn create_entities(scene: &mut Scene){
    // Create a sphere geometry and register it in the scene so we can use it later.
    // as a return value we get it's entity id
    let sphere = sphere_texcoords(0.1, 20, 20);
    let sphere = scene.register_mesh(sphere);

    // Create a new material of with a red color
    let material = StandardMaterialBuilder::default()
    let material = scene.register_material("material", material);

    // Create multiple models using the previous material and geometry
    for y in (-60 .. 60).step_by(2){
        let fy = y as f32 / 10.;
        for x in (-100 .. 100).step_by(2){
            let fx = x as f32 / 10.;
            scene.add_model(&format!("sphere{}_{}", x,y))
                .transformation(pnt3(fx, fy, 0.))

    let _light = scene.add_directional_light("DirLight")
        .transformation(Node::new_look_at(pnt3(3., 3., 3.), Pnt3::origin(), Vec3::y()))

    // Add a camera to the scene
    let events_stream = scene.event_stream();
    let window_size = scene.viewport().size();
    let camera = arcball_camera::Builder::new(events_stream, window_size)
        .position(pnt3(0., 3., 3.))

To learn more about the scene module check it’s own reference: scene

Immediate renderer + ECS

In some cases we might want to use ECS but not the full scene. In that case we can create a new application using the immediate parameter for cargo rin:

cargo rin new --immediate basic_example

An immediate renderer app looks like this:

pub fn setup(window: Window, gl: gl::Renderer<'static>, events: EventsPoll) -> Scene {
    let mut scene_builder = SceneBuilder::new(events);


    let renderer = ImmediateRenderer{ renderer: gl, window, system: render};
    let mut scene = scene_builder.with_renderer(renderer).build();


#[update_system(name = "update")]
fn update(clock: &Clock, entities: Entities, resources: Resources) {


#[render_system(name = "renderer")]
fn render(
    gl: &gl::Renderer,
    viewport: Rect<i32>,
    entities: EntitiesThreadLocal,
    resources: ResourcesThreadLocal)
    let gl = gl.with_mvp(Mvp::ortho_top_left(viewport));

Where we have one or more update systems and usually a render one.

To learn more about the immediate renderer check it’s own reference: scene::immediate_renderer

Learning rust

For more information on using rust, you can check the rust book


You can find examples on how to use rin at: https://…


The rin book has more in-depth documentation on how to use rin by showing examples for the main functionalities:

API reference



The blender module allows to import blender files into the scene, including geometry, materials, skeletons, animations, lights and more




Materials in mutiny. This module is renderer independent and the Components in it only specify materials data and some utilities. Each specific renderer should read this components in the scene and implement their behaivour


This module mostly re-exports na (a graphics oriented wrapper for nalgebra) angle (a type safe wrapper for angle measseures) and adds a few simple functions useful for graphics math


Prelude mod to make it easier to use rin, on applications import preamble like:


Mutiny is part of the rin ecosystem of rust crates for creative expression with code.




Type Definitions