Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

Repository files navigation

DynoWorld - Rust Port

Complete Rust port of the cel-shaded spinning cubes OpenGL demo.

Quick Start

Build and Run

cargo run --release

Build Only

cargo build --release

The executable will be at target/release/dynoworld-rust.exe

Controls

  • Mouse Movement: Rotate camera (orbital)
  • Mouse Scroll: Zoom in/out
  • ESC: Toggle mouse capture on/off
  • +/=: Increase light brightness
  • -: Decrease light brightness

Project Structure

dynoworld/
├── Cargo.toml              # Rust dependencies
├── build.rs                # OpenGL bindings generator
├── src/
│   ├── main.rs             # Rust port (680 lines)
│   └── shaders/
│       ├── vertex.glsl     # Vertex shader (unchanged)
│       └── fragment.glsl   # Fragment shader (unchanged)

Architecture

Rust-Specific Features

  1. Memory Safety: All OpenGL calls wrapped in unsafe blocks
  2. Ownership Model: Clear ownership of vertex data, camera state
  3. Pattern Matching: Event handling using Rust's match expressions
  4. Type Safety: Strongly typed matrices, cubes, camera

Direct C++ → Rust Translations

C++ Rust
float m[16] m: [f32; 16]
struct Mat4 { ... } struct Mat4 { ... }
Global variables Module-level mutable state
Manual memory management Automatic via ownership
Callbacks (function pointers) Event polling with match

Key Differences from C++ Version

  1. No global state mutation: Camera and cubes are local to main()
  2. Event polling vs callbacks: Rust GLFW uses iterator pattern
  3. Explicit unsafe blocks: All OpenGL FFI calls marked unsafe
  4. Vec instead of arrays: Dynamic vertex data storage
  5. Pattern matching: Cleaner input handling than if/else chains

Dependencies

  • glfw (0.58): Window management and input
  • gl (0.14): OpenGL 3.3 bindings
  • gl_generator (0.14): Build-time GL function loading

Performance

Compiled with --release flag for optimization:

  • Same rendering performance as C++ version
  • Zero-cost abstractions
  • LLVM optimizations enabled

Shaders

The GLSL shaders are 100% identical to the C++ version:

  • Vertex shader: Position transformation, normal calculation
  • Fragment shader: Cel shading with 4-level quantization, rim lighting

Differences from C++

Better

  • Type safety (no implicit casts)
  • Memory safety (no use-after-free)
  • Pattern matching (cleaner control flow)
  • Cargo dependency management

Trade-offs

  • More verbose (explicit types, unsafe blocks)
  • Steeper learning curve (ownership model)
  • Larger binary size (includes Rust std)

Build Artifacts

  • Debug build: target/debug/dynoworld-rust.exe (~10MB)
  • Release build: target/release/dynoworld-rust.exe (~2MB)
  • Incremental compilation cache in target/

Future Enhancements

Consider using:

  • glium: Safe OpenGL wrapper (reduces unsafe code)
  • nalgebra or cgmath: Mature linear algebra libraries
  • wgpu: Modern graphics API (Vulkan/Metal/DX12)

About

a 3d exploration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages