Giter VIP home page Giter VIP logo

deno_sdl2's Introduction

Deno SDL2

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

Screen.Recording.2022-03-28.at.5.37.35.PM.mov

get started

import { EventType, WindowBuilder } from "https://deno.land/x/sdl2/mod.ts";

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

for (const event of window.events()) {
  if (event.type == EventType.Quit) {
    break;
  } else if (event.type == EventType.Draw) {
    // Rainbow effect
    const r = Math.sin(Date.now() / 1000) * 127 + 128;
    const g = Math.sin(Date.now() / 1000 + 2) * 127 + 128;
    const b = Math.sin(Date.now() / 1000 + 4) * 127 + 128;
    canvas.setDrawColor(Math.floor(r), Math.floor(g), Math.floor(b), 255);
    canvas.clear();
    canvas.present();
  }
}
~> deno run --allow-ffi --unstable https://deno.land/x/sdl2/examples/hello.ts

installing sdl2

Follow https://wiki.libsdl.org/Installation to install the dynamic library.

TL;DR

MacOS (arm64/x64):

brew install sdl2 sdl2_image sdl2_ttf

Windows (x64): Grab one of the prebuilt libraries from https://buildbot.libsdl.org/sdl-builds/sdl-visualstudio-x86/ 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/

security

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

license

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.