search


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:

  1. Create a device and an adapter.
  2. Create a shader module for your triangle.
  3. Create a pipeline layout for your triangle.
  4. Create a pipeline for your triangle.
  5. Create a vertex buffer for your triangle.
  6. Create a command encoder.
  7. Begin a render pass.
  8. Set the pipeline.
  9. 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