Small PHP FFI bindings for SDL3 and SDL3_ttf.
This package was split out from the overlay demo so it can be reused as an independent Composer library.
- PHP 8.4 or later
ext-ffi- SDL3
- SDL3_ttf
- Apache-2.0 license
composer require hanhan1978/ffi-sdl3:^0.1If you are developing against a local checkout, add a path repository to the
parent project's composer.json and run composer install.
{
"repositories": [
{
"type": "path",
"url": "../ffi-sdl3"
}
]
}use SDL3\BlendMode;
use SDL3\Color;
use SDL3\SDL;
use SDL3\TTF\Font;
use SDL3\TTF\TTF;
use SDL3\Window;
use SDL3\WindowFlag;
$sdl = SDL::init();
$ttf = TTF::init($sdl);
$font = new Font($ttf, '/System/Library/Fonts/Helvetica.ttc', 32.0);
$window = new Window($sdl, 'Overlay', 640, 80, [
WindowFlag::Borderless,
WindowFlag::AlwaysOnTop,
WindowFlag::Transparent,
]);
$renderer = $window->createRenderer();
$renderer->setDrawBlendMode(BlendMode::Blend);
$surface = $font->renderTextBlended('Hello', new Color(255, 230, 80));
$texture = $renderer->createTextureFromSurface($surface);
$surface->destroy();LibraryFinder searches for SDL3 and SDL3_ttf in this order:
SDL3_LIBRARY_PATHSDL3_TTF_LIBRARY_PATHpkg-config- Common Homebrew paths
SDL3\SDLSDL3\WindowSDL3\RendererSDL3\TextureSDL3\SurfaceSDL3\RectSDL3\ColorSDL3\WindowFlagSDL3\BlendModeSDL3\Event\*SDL3\TTF\TTFSDL3\TTF\Font
Apache-2.0