Skip to content

Latias94/learn_opengl_rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learn OpenGL in Rust

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.

Chapters

1_3_2 1_4_2 1_7_3

2_2_1 2_4_2 2_6_1

3_1_1 3_1_1-web

4_3_2 4_5_2 4_6_2

4_9_2 4_9_3 4_10_3

5_2_1 5_3_3

Notes

  • The function to load models and textures is implemented in resources.rs. Basically build.rs file will copy all resources to the output directory, so we can use relative path to load resources. For wasm, build.rs file will also copy resources to web directory, then we can download them from the local server.
  • I use tobj crate to load models, thus support .obj format only.
  • I use include_str! macro to load shaders for simplicity.
  • egui only 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.

Build

Prerequisites

Install Just, a handy command runner. Or you can run command found in justfile manually.

Desktop

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 imgui

WebGL

wasm-pack (Recommended)

wasm-pack has bundled WebAssembly/binaryen for you, which can optimize wasm file.

  1. Install wasm-pack.
  2. 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

wasm-bindgen

Alternatively, use wasm-bindgen directly for a less optimized build.

  1. Install wasm32-unknown-unknown target and wasm-bindgen-cli:
    rustup target add wasm32-unknown-unknown
    cargo install wasm-bindgen-cli
  2. To build and run with wasm-bindgen, then visit http://127.0.0.1:8000/?tutorial=1_2_1.
    just web-bindgen

About

Following https://learnopengl.com/ with Rust, compatible with both desktop and WebGL via WebAssembly (wasm).

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages