PHPackages                             serafim/ffi-sdl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. serafim/ffi-sdl

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

serafim/ffi-sdl
===============

SDL FFI bindings for the PHP language

2.0.1(1y ago)314.6k53MITCPHP ^8.1

Since Apr 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/SerafimArts/ffi-sdl)[ Packagist](https://packagist.org/packages/serafim/ffi-sdl)[ Docs](https://github.com/SerafimArts/ffi-sdl)[ RSS](/packages/serafim-ffi-sdl/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (12)Versions (11)Used By (3)

FFI SDL Bindings
================

[](#ffi-sdl-bindings)

 [![PHP 8.1+](https://camo.githubusercontent.com/3db8773f36364ec3eceeb33d89dd75471f651540f7a4a83074e8e4d7d4756570/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/ffi-sdl) [![SDL](https://camo.githubusercontent.com/76d7bb3233236ddec06168c51bb1a8658389a437cc6968de807ff50a9fc86870/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53444c2d322e32382e322d3133324234382e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d63253262253262)](https://github.com/libsdl-org/SDL) [![Latest Stable Version](https://camo.githubusercontent.com/de1ada316c5df4ae52a8a23e1b9b4d98c6867e4107d1003d2d6b1550110dad8a/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/ffi-sdl) [![Latest Unstable Version](https://camo.githubusercontent.com/65dade4c830ea7658e5c5ab0c604eb767b0299073d11a3bcb1ae3b2197e0d7c7/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/ffi-sdl) [![Total Downloads](https://camo.githubusercontent.com/d9c42cf03fcffd625b6545cd17cc00c1ef7050855210bb6ab222880502119c19/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2f646f776e6c6f6164733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/ffi-sdl) [![License MIT](https://camo.githubusercontent.com/943020e6d95437f6fac82c04685ac04cb08f4c4d4a636b4cb0c9567a8e9c4d69/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/serafim/ffi-sdl/master/LICENSE.md)

A SDL FFI bindings for the PHP language.

- [System Requirements](#requirements)
- [Installation](#installation)
- [Extensions](#extensions)
- [Documentation](#documentation)
- [Initialization](#initialization)
- [Example](#example)

Requirements
------------

[](#requirements)

- PHP ^8.1
- ext-ffi
- Windows, Linux, BSD or MacOS
    - Android, iOS or something else are not supported yet
- SDL &gt;= 2.0

Installation
------------

[](#installation)

Library is available as composer repository and can be installed using the following command in a root of your project.

```
$ composer require serafim/ffi-sdl
```

Additional dependencies:

- Debian-based Linux: `sudo apt install libsdl2-2.0-0 -y`
- MacOS: `brew install sdl2`
- Window: Can be [downloaded from here](https://github.com/libsdl-org/SDL/releases)

Extensions
----------

[](#extensions)

- [SDL Image](https://github.com/SerafimArts/ffi-sdl-image)
- [SDL TTF](https://github.com/SerafimArts/ffi-sdl-ttf)
- [SDL Mixer](https://github.com/SerafimArts/ffi-sdl-mixer)

Documentation
-------------

[](#documentation)

The library API completely supports and repeats the analogue in the C language.

- [SDL2 official documentation](https://wiki.libsdl.org/FrontPage)
- API not yet fully documented and may not work in places.
- Low level and inline functions (such as `SDL_malloc` or `SDL_memcpy`) have been removed.

Initialization
--------------

[](#initialization)

To specify a library pathname explicitly, you can add the `library` argument to the `Serafim\SDL\SDL` constructor.

> By default, the library will try to resolve the binary's pathname automatically.

```
// Load library from pathname (it may be relative or part of system-dependent path)
$sdl = new Serafim\SDL\SDL(library: __DIR__ . '/path/to/library.so');

// Try to automatically resolve library's pathname
$sdl = new Serafim\SDL\SDL(library: null);
```

You can explicitly specify the platform (OS) that will be used as the basis for compiling headers.

> By default, the library will try to resolve the platform automatically.

```
// Use Linux as compile-aware platform
$sdl = new Serafim\SDL\SDL(platform: Serafim\SDL\Platform::LINUX);

// Detect platform automatically
$sdl = new Serafim\SDL\SDL(platform: null);
```

You can also specify the library version explicitly. Depending on this version, the corresponding functions of the SDL will be available.

> By default, the library will try to resolve SDL version automatically.

```
// Use v2.28.2 from string
$sdl = new Serafim\SDL\SDL(version: '2.28.2');

// Use v2.24.1 from predefined versions constant
$sdl = new Serafim\SDL\SDL(version: \Serafim\SDL\Version::V2_24_1);

// Use latest supported version
$sdl = new Serafim\SDL\SDL(version: \Serafim\SDL\Version::LATEST);
```

To speed up the header compiler, you can use any PSR-16 compatible cache driver.

```
$sdl = new Serafim\SDL\SDL(cache: new Psr16Cache(...));
```

In addition, you can control other preprocessor directives explicitly:

```
$pre = new \FFI\Preprocessor\Preprocessor();
$pre->setLogger(new ExampleLogger());
$pre->define('__ANDROID__', '1');

$sdl = new Serafim\SDL\SDL(pre: $pre);
$jni = $sdl->SDL_AndroidGetJNIEnv();
```

Example
-------

[](#example)

```
use Serafim\SDL\SDL;
use Serafim\SDL\Event\Type;

$sdl = new SDL();

$sdl->SDL_Init(SDL::SDL_INIT_VIDEO);

$window = $sdl->SDL_CreateWindow(
    'An SDL2 window',
    SDL::SDL_WINDOWPOS_UNDEFINED,
    SDL::SDL_WINDOWPOS_UNDEFINED,
    640,
    480,
    SDL::SDL_WINDOW_OPENGL
);

if ($window === null) {
    throw new \Exception(sprintf('Could not create window: %s', $sdl->SDL_GetError()));
}

$event = $sdl->new('SDL_Event');
$running = true;

while ($running) {
    $sdl->SDL_PollEvent(FFI::addr($event));
    if ($event->type === Type::SDL_QUIT) {
        $running = false;
    }
}

$sdl->SDL_DestroyWindow($window);
$sdl->SDL_Quit();
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~188 days

Recently: every ~120 days

Total

10

Last Release

530d ago

Major Versions

1.0.4 → 2.0.0-beta12023-08-09

PHP version history (2 changes)1.0.0PHP &gt;=7.4

2.0.0-beta1PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (46 commits)")

---

Tags

ffiopenglphpsdlsdl2sdl2-bindingslibrarygraphicsffibindingsopenglsdldirect media

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/serafim-ffi-sdl/health.svg)

```
[![Health](https://phpackages.com/badges/serafim-ffi-sdl/health.svg)](https://phpackages.com/packages/serafim-ffi-sdl)
```

###  Alternatives

[league/iso3166

ISO 3166-1 PHP Library

70036.3M116](/packages/league-iso3166)[dekor/php-array-table

PHP Library for printing associative arrays as text table (similar to mysql terminal console)

296.6M2](/packages/dekor-php-array-table)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
