Following learnopengl.com with Rust, compatible with both desktop and WebGL via WebAssembly (wasm).
Using glow, glutin, winit, winit_input_helper, nalgebra-glm etc.
This project make some different choices from the original tutorial, such as window abstraction, input handling, camera control etc.
- The function to load models and textures is implemented in
resources.rs. Basicallybuild.rsfile will copy all resources to the output directory, so we can use relative path to load resources. For wasm,build.rsfile will also copy resources towebdirectory, then we can download them from the local server. - I use
tobjcrate to load models, thus support.objformat only. - I use
include_str!macro to load shaders for simplicity. eguionly used on desktop for now.- WebGL2 don't support geometry shader (
4_9_1) and interface blocks. - OpenGL debug messages are only available on desktop debug build.
Install Just, a handy command runner. Or you can run
command found in justfile manually.
just run 1_2_1 # Debug build then Run tutorial 1_2_1
just rrun 3_1_1 # Release build then run tutorial 3_1_1
cargo r --features egui-support -- 4_5_2 # Run tutorial 4_5_2 with egui
cargo r --features imgui-support -- 4_5_2 # Run tutorial 4_5_2 with imguiwasm-pack has bundled WebAssembly/binaryen for you, which can optimize wasm
file.
- Install wasm-pack.
- To build and run with wasm-pack (generates an optimized wasm file), then visit http://127.0.0.1:8000/?tutorial=1_2_1.
just web
Alternatively, use wasm-bindgen directly for a less optimized build.
- Install
wasm32-unknown-unknowntarget andwasm-bindgen-cli:rustup target add wasm32-unknown-unknown cargo install wasm-bindgen-cli
- To build and run with wasm-bindgen, then visit http://127.0.0.1:8000/?tutorial=1_2_1.
just web-bindgen















