Perl bindings for SDL 3 - Simple DirectMedia Layer - the cross-platform development library that provides low level access to audio, keyboard, mouse, joystick, and graphics hardware.
The Perl-SDL3 organization maintains a modern, pure-Perl FFI wrapper around SDL 3 built on Affix, plus the Alien:: distributions that build and install SDL and its satellite libraries for you.
| Repository | Description |
|---|---|
| SDL3.pm | The wrapper itself bound through Affix [CPAN] |
| Alien-SDL3.pm | Builds and installs SDL3 [CPAN] |
| Alien-SDL3_image.pm | Builds and installs SDL3_image |
| Alien-SDL3_mixer.pm | Builds and installs SDL3_mixer |
| Alien-SDL3_ttf.pm | Builds and installs SDL3_ttf |
| Alien-SDL3_net.pm | Builds and installs SDL3_net |
| Alien-SDL3_rtf.pm | Builds and installs SDL3_rtf |
A few of the demos in the eg/ directory of SDL3.pm, captured live:
Synopsis - the module's synopsis: a bouncing box driven by SDL3's callback-based :main app framework, in basics/synopsis.pl.
Tetris - a complete tetromino game with next-piece preview, landing shadow, and scoring, in games/tetris.pl.
Particle waterfall - 1,000 particles that flow between five overlapping windows, hopping from one to the next based on SDL3 window z-order, in basics/particle_waterfall.pl.
Install from CPAN:
cpanm SDL3Alien::SDL3 is pulled in as a dependency and handles obtaining the SDL3 native library. Then:
use v5.40;
use SDL3 qw[:all :main];
my ( $x, $y, $dx, $dy, $ren ) = ( 300, 200, 5, 5 );
sub SDL_AppInit( $app, $ac, $av ) {
state $win;
SDL_Init(SDL_INIT_VIDEO);
SDL_CreateWindowAndRenderer( 'Bouncing Box', 640, 480, 0, \$win, \$ren );
SDL_SetRenderVSync( $ren, 1 );
SDL_APP_CONTINUE;
}
sub SDL_AppEvent( $app, $ev ) {
$ev->{type} == SDL_EVENT_QUIT ? SDL_APP_SUCCESS : SDL_APP_CONTINUE;
}
sub SDL_AppIterate($app) {
$dx *= -1 if $x <= 0 || $x >= 620;
$dy *= -1 if $y <= 0 || $y >= 460;
$x += $dx;
$y += $dy;
SDL_SetRenderDrawColor( $ren, 20, 20, 30, 255 );
SDL_RenderClear($ren);
SDL_SetRenderDrawColor( $ren, int($x) % 255, int($y) % 255, 200, 255 );
SDL_RenderFillRect( $ren, { x => $x, y => $y, w => 20, h => 20 } );
SDL_RenderPresent($ren);
SDL_APP_CONTINUE;
}
sub SDL_AppQuit { }- SDL3 on CPAN
- SDL3 Wiki - reference for the underlying API
- Affix - the FFI library that powers the wrapper
See CONTRIBUTING.md for how to report bugs, set up a development environment, and submit changes. Questions and feedback are welcome.
Code in this organization is licensed under the Artistic License 2.0. Documentation and other content is licensed under CC BY 4.0. Individual repositories may carry their own licenses; see each repository's LICENSE file.