Draw triangle with WGPU and Rust
Mon Sep 25 00:00:00 UTC 2023
Drawing a simple triangle with low-level graphics API like WGPU is not easy.
Here is an summary:
- Create a device and an adapter.
- Create a shader module for your triangle.
- Create a pipeline layout for your triangle.
- Create a pipeline for your triangle.
- Create a vertex buffer for your triangle.
- Create a command encoder.
- Begin a render pass.
- Set the pipeline.
- Draw your triangle.
Building for WASM
install wasm-pack#install a webserver to serve the html,js,wasm files
% npm install -g http-server
# change into your project dir
% cd your-project
# use wasm-pack to build
% wasm-pack build --release --target web
# start webserver
% http-server
open in browser http://localhost:8080/index.html