willow_example/
lib.rs

1//! Example webapp using [`willow`](https://docs.rs/willow/).
2
3#![allow(clippy::blacklisted_name)]
4#![warn(missing_docs)]
5
6use nalgebra::{Matrix4, Vector3};
7use wasm_bindgen::prelude::*;
8use willow::{Attribute, Context, Program, ProgramData, Uniform};
9
10/// This type wraps the program with the `foo.vert` and `foo.frag` shaders.
11#[derive(Program)]
12#[willow(path = "foo")]
13pub struct Foo {
14    data: ProgramData,
15    u_alpha: Uniform<f32>,
16    u_transform: Uniform<Matrix4<f32>>,
17    a_color: Attribute<Vector3<f32>>,
18    a_offset: Attribute<Vector3<f32>>,
19}
20
21/// WebGL entry function.
22#[wasm_bindgen(start)]
23pub fn main() {
24    std::panic::set_hook(Box::new(console_error_panic_hook::hook));
25    wasm_logger::init(wasm_logger::Config::default());
26
27    let canvas = web_sys::window()
28        .unwrap()
29        .document()
30        .unwrap()
31        .get_element_by_id("canvas")
32        .unwrap();
33
34    let context = Context::from_canvas(canvas).unwrap();
35    let (foo,) = willow::create_programs!(context => Foo);
36}