This is a SDL bindings for PHP
- PHP >= 7.4
- ext-ffi
- Windows, Linux or MacOS
- Android, iOS, BSD or something else are not supported yet
- SDL >= 2.0
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
sudo apt install libsdl2-2.0-0 -y
brew install sdl2
- SDL (2.0.12) binaries are already bundled
The library API completely supports and repeats the analogue in the C language.
- API not yet fully documented and may not work in places.
- Low level system functions (such as
SDL_malloc
orSDL_memcpy
) have been removed.
use Serafim\SDL\SDL;
use Serafim\SDL\Event;
use Serafim\SDL\Kernel\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(Event::class);
$running = true;
while ($running) {
$sdl->SDL_PollEvent(SDL::addr($event));
if ($event->type === Type::SDL_QUIT) {
$running = false;
}
}
$sdl->SDL_DestroyWindow($window);
$sdl->SDL_Quit();