2 releases

0.3.1 Feb 6, 2022
0.3.0 Feb 6, 2022

#760 in Graphics APIs

33 downloads per month

MIT license

1.5MB
1.5K SLoC

Rust 881 SLoC // 0.1% comments TypeScript 733 SLoC // 0.2% comments

Deno SDL2

Cross platform bindings to SDL2. Have fun!

Features

  • Bindings to Video, Graphics, Font and Mixer subsystems. (Uses rodio instead of SDL2_Mixer)
  • Built on top of Deno's FFI API. Previous versions used TCP streams.

Example

import { Canvas } from "https://deno.land/x/sdl2/src/canvas.ts";

const canvas = new Canvas({
  title: "Hello, Deno!",
  height: 800,
  width: 600,
  centered: true,
  fullscreen: false,
  hidden: false,
  resizable: true,
  minimized: false,
  maximized: false,
  flags: null,
});

canvas.setDrawColor(0, 64, 255, 255);
canvas.clear();
canvas.present();

for await (const event of canvas) {
  switch (event.type) {
    case "draw":
      // Your game logic
      // ...
      break;
    case "mouse_motion":
      // Mouse stuff
      break;
    case "key_down":
      // Keyboard stuff
      break;
    // ...
    default:
      break;
  }
}

Building from source

You need:

  • deno_bindgen CLI from the main branch
  • Rust nightly toolchain + Cargo (1.57.0-nightly)
  • cargo-vcpkg tool
  • pkg-config (on *nix) => brew install pkg-config
deno install -Afq -n deno_bindgen https://deno.land/x/deno_bindgen/cli.ts
cargo install cargo-vcpkg

# build vcpkg dependencies
cargo vcpkg -v build

Build using:

deno_bindgen -- --features "use_vcpkg"

Projects using deno_sdl2

License

MIT

Dependencies

~22MB
~473K SLoC