Giter Club home page Giter Club logo

sdl_ts's Introduction

SDL_ts

SDL bindings for TypeScript.

Currently working via deno on Windows, Linux, and mac OS using FFI (Foreign Function Interface).

Primary Goals

  • Resembling the C API as much as possible. If someone reads a SDL tutorial (for example LazyFoo) then they should be able to easily translate the tutorial to the equivalent in this library.

Secondary Goals

  • Provide utiltiy functions which wrap SDL features into idomatic JavaScript (i.e. Events.asyncIterator).

Non Goals

  • Creating a higher level API or Game Framework. This library's only purpose is to expose the SDL API to deno.

Getting Started

SDL2 Installation

Linux

Debain
sudo apt install libsdl2-2.0-0 libsdl2-image-2.0-0 libsdl2-ttf-2.0-0
Fedora
sudo dnf install SDL2 SDL2_image SDL2_ttf

Windows

MSYS2
pacman -S mingw-w64-ucrt-x86_64-SDL2 mingw-w64-ucrt-x86_64-SDL2_image mingw-w64-ucrt-x86_64-SDL2_ttf

You'll need to ensure then that the sysroot (in this case ucrt) is in your path. Assuming the default install location for msys2 then C:\msys64\ucrt64\bin.

MacOS

Homebrew
brew install sdl2 sdl2_image sdl2_ttf

Creating a Project

To aid in creating a new project which uses SDL_ts there is an init.ts script to aid in getting your project set up:

deno run --allow-net --allow-read=/path/to/project --allow-write=/path/to/project --import-map https://deno.land/x/[email protected]/imports.deno.json https://deno.land/x/[email protected]/init.ts /path/to/project

Replace /path/to/project with the desired project path. After that the new project can be started via a deno task:

deno task start

You should be presented with a window titled "SDL_ts".

Loading only required functions

Per default SDL.Init (or IMG.Init or TTF.Init) will load all known functions from the SDL assemblies. This can be problematic when attempting to run your script on an older version of the SDL assemblies than the version against which this library is developed. The Init functions accept an options parameter in which the functions to load can be specified:

SDL.Init(SDL.InitFlags.VIDEO, {
  functions: [
    SDL.Init,
    SDL.PollEvent,
    SDL.Quit,
    // And so on
  ],
});

Credits

Deno images taken from https://deno.land/artwork.

Thanks to:

sdl_ts's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sdl_ts's Issues

not working on Mac x64

brew install sdl2 sdl2_image sdl2_ttf

dir_path=sdl
if [ ! -d "$dir_path" ]; then
    mkdir $dir_path
fi

projectPath=`pwd`
deno run --allow-net --allow-read="$projectPath" --allow-write="$projectPath" --import-map https://deno.land/x/[email protected]/imports.deno.json https://deno.land/x/[email protected]/init.ts "$projectPath"

sdl deno task start

// return
error: Uncaught (in promise) Error: Failed to load library "darwin/x64/libSDL2.a"
    throw new SDLError(`Failed to load library "${libraryPath}"`, error);
          ^
    at loadLibrary (https://deno.land/x/[email protected]/src/deno/_library.ts:25:11)
    at Module.Init (https://deno.land/x/[email protected]/src/SDL/functions.ts:330:14)
    at main (file:///Users/jonham/code/sdl2-deno/sdl/main.ts:4:7)
    at file:///Users/jonham/code/sdl2-deno/sdl/main.ts:38:11
Caused by: Error: Could not open library: Could not open library: dlopen(darwin/x64/libSDL2.a, 0x0005): tried: 'darwin/x64/libSDL2.a' (not a mach-o file), '/System/Volumes/Preboot/Cryptexes/OSdarwin/x64/libSDL2.a' (no such file), '/usr/lib/darwin/x64/libSDL2.a' (no such file, not in dyld cache), 'darwin/x64/libSDL2.a' (not a mach-o file), '/Users/jonham/code/sdl2-deno/sdl/darwin/x64/libSDL2.a' (not a mach-o file), '/System/Volumes/Preboot/Cryptexes/OS/Users/jonham/code/sdl2-deno/sdl/darwin/x64/libSDL2.a' (no such file), '/Users/jonham/code/sdl2-deno/sdl/darwin/x64/libSDL2.a' (not a mach-o file)

Error: Failed to load library "SDL2" from ""

When I clone the repo and attempt to run any of the demos from a windows powershell, I see the following:

PS C:\Users\andyb\src\SDL_ts> deno task run:doom-fire
Task run:doom-fire export SDL_TS_ENV_DIR=$INIT_CWD && cd ./examples/doom-fire && deno run --unstable --allow-env --allow-ffi --allow-read=../.. $DENO_FLAGS ./main.ts
Error: Failed to load library "SDL2" from ""
    at Function.denoLoadLibrary [as loadLibrary] (file:///C:/Users/andyb/src/SDL_ts/src/deno/_library.ts:123:9)
    at Module.Init (file:///C:/Users/andyb/src/SDL_ts/src/SDL/functions.ts:353:23)
    at main (file:///C:/Users/andyb/src/SDL_ts/examples/doom-fire/main.ts:53:7)
    at file:///C:/Users/andyb/src/SDL_ts/examples/doom-fire/main.ts:191:13
Caused by AggregateError
    at Function.denoLoadLibrary [as loadLibrary] (file:///C:/Users/andyb/src/SDL_ts/src/deno/_library.ts:125:5)
    at Module.Init (file:///C:/Users/andyb/src/SDL_ts/src/SDL/functions.ts:353:23)
    at main (file:///C:/Users/andyb/src/SDL_ts/examples/doom-fire/main.ts:53:7)
    at file:///C:/Users/andyb/src/SDL_ts/examples/doom-fire/main.ts:191:13
PS C:\Users\andyb\src\SDL_ts> ls

It seems the .env.windows file is not loading correctly. Any ideas? Let me know if you need more info.

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.