Skip to content

A minimal example of using Rust, wgpu, and egui without using eframe 🦀 Works on Windows/Linux/MacOS/Web/Android/OpenXR (Such as Quest 3 + Virtual Desktop)

Notifications You must be signed in to change notification settings

matthewjberger/wgpu-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust / Winit / Egui / Wgpu Triangle

A cross-platform Rust graphics demo using wgpu to render a spinning triangle. Supports native desktop, WebGL/WebGPU (WASM), Android, Steam Deck, and OpenXR VR with hand tracking.

Related Projects:

native

Other languages (experimental):

Quickstart

Platform Command
Native Desktop cargo run -r
WebGPU trunk serve --features webgpu --open
WebGL trunk serve --features webgl --open
Android just run-android DEVICE_ID
Steam Deck just build-steamdeck && just deploy-steamdeck
OpenXR VR (Desktop) just run-openxr
OpenXR VR (Quest) just build-android-openxr

Platform Setup

Web (WebAssembly)

Prerequisites: trunk

Browser Support: All Chromium-based browsers (Chrome, Brave, Vivaldi) support WebGPU. Firefox supports WebGPU starting with version 141 (announcement).

Android

Prerequisites:

  • xbuild
  • Android SDK and NDK
  • Connected Android device or emulator (API level 24+)

First-time setup:

just init-android

Build and run:

just list-android          # Find your device ID
just run-android DEVICE_ID # e.g., just run-android RFCY61DZZKT

Connect via USB with USB debugging enabled, or use wireless debugging (see below).

The build uses --features android which enables wgpu's Vulkan backend.

Wireless Debugging Setup
  1. Enable Developer options: Settings > About phone > tap Build number 7 times
  2. Disable auto-blocker if present (Samsung): Settings > Security > Auto Blocker
  3. Enable wireless debugging: Settings > Developer options > Wireless debugging
  4. Tap Pair device with pairing code and note the IP:port
  5. Pair and connect:
    just pair-android 192.168.1.100:37000  # Enter pairing code when prompted
    just list-android                       # Get device ID
    just run-android DEVICE_ID
Additional Android Commands
just build-android              # Build only (windowed app)
just build-android-all          # Build for arm64 and x64
just build-android-openxr       # Build for Meta Quest VR
just install-android DEVICE_ID  # Install without running
just connect-android IP:PORT    # Connect over wireless ADB
just list-android               # List connected devices

Steam Deck

Prerequisites:

  • cross
  • Docker (for cross-compilation)

First-time setup:

just init-steamdeck

Build and deploy:

just build-steamdeck   # Cross-compiles to target/x86_64-unknown-linux-gnu/release/app
just deploy-steamdeck  # Transfers to steamdeck.local:~/Downloads

Run on Steam Deck:

just steamdeck-ssh
cd ~/Downloads && ./app

The Cross.toml file configures system libraries for graphics and windowing support.

OpenXR VR Mode (Desktop)

Renders the spinning triangle with an infinite grid, procedural skybox, and hand tracking in VR via PCVR streaming.

Setup:

  1. Install SteamVR
  2. Install Virtual Desktop or another OpenXR-compatible runtime
  3. Start Virtual Desktop and stream your desktop to your VR headset
  4. Run just run-openxr on your desktop

OpenXR VR Mode (Meta Quest)

Native standalone VR for Meta Quest 2, Quest Pro, Quest 3, and Quest 3S.

Prerequisites:

  • All Android prerequisites (see above)
  • Meta Quest device with Developer Mode enabled

Build:

just build-android-openxr

This produces an APK at target/x/release/android/app.apk.

Install on Quest:

adb install -r target/x/release/android/app.apk

Or use SideQuest to drag and drop the APK onto your Quest.

The app appears in your Quest library under "Unknown Sources".

Technical Notes
  • Uses the android-openxr feature which combines android and openxr features
  • Bundles Meta's OpenXR loader from libs/arm64-v8a/libopenxr_loader.so
  • Manifest includes com.oculus.intent.category.VR for proper VR app handling
  • Supports Quest hand tracking and controller input
  • Requires manifest.yaml with runtime_libs configuration for library bundling

Screenshots

webgl webgpu

About

A minimal example of using Rust, wgpu, and egui without using eframe 🦀 Works on Windows/Linux/MacOS/Web/Android/OpenXR (Such as Quest 3 + Virtual Desktop)

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

 

Contributors 3

  •  
  •  
  •