Skip to main content

Deno SDL2

deno_sdl2 provides cross-platform bindings to sdl2, sdl2_ttf and sdl2_image.

get started

import { EventType, WindowBuilder } from "";

const window = new WindowBuilder("Hello, Deno!", 640, 480).build();
const canvas = window.canvas();

for (const event of {
  if (event.type == EventType.Quit) {
  } else if (event.type == EventType.Draw) {
    // Rainbow effect
    const r = Math.sin( / 1000) * 127 + 128;
    const g = Math.sin( / 1000 + 2) * 127 + 128;
    const b = Math.sin( / 1000 + 4) * 127 + 128;
    canvas.setDrawColor(Math.floor(r), Math.floor(g), Math.floor(b), 255);
~> deno run --allow-ffi --unstable

installing sdl2

Follow to install the dynamic library.


MacOS (arm64/x64):

brew install sdl2 sdl2_image sdl2_ttf

Windows (x64): Grab one of the prebuilt libraries from and put lib/SDL2.dll into the root of your project.

Linux (x64):

sudo apt install sdl2 sdl2_image sdl2_ttf

Make sure the libraries is in your system’s library search paths, if not already:

sudo ln -s /opt/homebrew/lib/libSDL2.dylib /usr/local/lib/
sudo ln -s /opt/homebrew/lib/libSDL2_image.dylib /usr/local/lib/
sudo ln -s /opt/homebrew/lib/libSDL2_ttf.dylib /usr/local/lib/


you need --allow-ffi --unstable to use SDL2. deno_sdl2 needs access to system’s SDL2 library. Deno’s permission model does not work well with FFI libraries, use at your own risk.

projects using deno_sdl2