Date: 14/12/2024
This is an example as an introduction to WGPU. In this example we simply draw the famous triangle on a window. This is based on the example from Learn WGPU (https://sotrh.github.io/learn-wgpu/) but refactored to update to the latest lib/API version. I also took inspiration from the Youtube series from GetIntoGameDev (https://www.youtube.com/watch?v=I8Uf7akOYo0).
Winit 0.30.5 has introduced breaking changes to its API. The examples on Learn GPU and GetIntoGameDev, no longer work with latest version of Winit and WGPU. I had troubles finding online documentation for Winit updated API.
Luckily I found this brilliant code that resolves the issue:
https://github.com/w4ngzhen/wgpu_winit_example
So credit to them! The refactoring around the window is neat using ARC to be able to get a reference on a mutable reference asynchronously.
-
for the desktop version simply run:
> cargo run
-
for the WASM browser version, you can install Trunk (https://trunkrs.dev/) and run :
> trunk serve
And open your navigator and enter the URL. Default is http://127.0.0.1:8080/
"I want to give a shoutout to Daxpedda for all the help with fixing and cleaning up the code, especially with the async stuff in WASM."