Notan

Portable Multimedia Layer


Notan is a simple and portable layer, designed to make your own multimedia apps on top of it without worrying too much about platform-specific code.

The main goal is to provide a set of APIs and tools that can be used to create your project in an ergonomic manner without enforcing any structure or pattern, always trying to stay out of your way.

Community

Examples

Do you want to open a window?

Window Open

```rust use notan::prelude::*;

[notan_main]

fn main() -> Result<(), String> { notan::init().build() } ```

Do you want to draw a triangle?

Draw Triangle

```rust use notan::prelude::; use notan::draw::;

[notan_main]

fn main() -> Result<(), String> { notan::init().draw(draw) .add_config(DrawConfig) .build() }

fn draw(gfx: &mut Graphics) { let mut draw = gfx.create_draw(); draw.clear(Color::BLACK); draw.triangle((400.0, 100.0), (100.0, 500.0), (700.0, 500.0)); gfx.render(&draw); } ```

How about render the triangle directly?

Renderer Triangle

```rust use notan::prelude::*;

//language=glsl const VERT: ShaderSource = notan::vertexshader! { r#" #version 450 layout(location = 0) in vec2 apos; layout(location = 1) in vec3 a_color;

layout(location = 0) out vec3 v_color;

void main() {
    v_color = a_color;
    gl_Position = vec4(a_pos - 0.5, 0.0, 1.0);
}
"#

};

//language=glsl const FRAG: ShaderSource = notan::fragment_shader! { r#" #version 450 precision mediump float;

layout(location = 0) in vec3 v_color;
layout(location = 0) out vec4 color;

void main() {
    color = vec4(v_color, 1.0);
}
"#

};

[derive(AppState)]

struct State { clear_options: ClearOptions, pipeline: Pipeline, vbo: Buffer, }

[notan_main]

fn main() -> Result<(), String> { notan::init_with(setup).draw(draw).build() }

fn setup(gfx: &mut Graphics) -> State { let clear_options = ClearOptions::color(Color::new(0.1, 0.2, 0.3, 1.0));

let vertex_info = VertexInfo::new()
    .attr(0, VertexFormat::Float32x2)
    .attr(1, VertexFormat::Float32x3);

let pipeline = gfx
    .create_pipeline()
    .from(&VERT, &FRAG)
    .with_vertex_info(&vertex_info)
    .build()
    .unwrap();

#[rustfmt::skip]
let vertices = [
    0.5, 1.0,   1.0, 0.2, 0.3,
    0.0, 0.0,   0.1, 1.0, 0.3,
    1.0, 0.0,   0.1, 0.2, 1.0,
];

let vbo = gfx
    .create_vertex_buffer()
    .with_info(&vertex_info)
    .with_data(&vertices)
    .build()
    .unwrap();

State {
    clear_options,
    pipeline,
    vbo,
}

}

fn draw(gfx: &mut Graphics, state: &mut State) { let mut renderer = gfx.create_renderer();

renderer.begin(Some(state.clear_options));
renderer.set_pipeline(&state.pipeline);
renderer.bind_buffer(&state.vbo);
renderer.draw(0, 3);
renderer.end();

gfx.render(&renderer);

} ```

Looking for more examples?

Sure! Check the examples folder. You will find there a few of them for any matter, like rendering, windowing, input, etc...

Installation

Add notan to your project from crates.io. The main branch should always be the latest version on crates.io.

WebAssembly

We treat the web as a first class citizen. WebAssembly compilation is dead simple, we recommend to just use trunk. You only need to add an index.html file to your project and run trunk serve to see it working.

Here is a simple index.html file as an example:

```html Notan App