Skip to content
@Perl-SDL3

Perl-SDL3

Perl-SDL3

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.

Repositories

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

Built with SDL3.pm

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.

Bouncing Box Demo from SDL3's Synopsis

Tetris - a complete tetromino game with next-piece preview, landing shadow, and scoring, in games/tetris.pl.

Tetris - A True Classic

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.

Particle Waterfall!!!

Getting started

Install from CPAN:

cpanm SDL3

Alien::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 { }

Documentation

Contributing

See CONTRIBUTING.md for how to report bugs, set up a development environment, and submit changes. Questions and feedback are welcome.

License

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.

Pinned Loading

  1. SDL3.pm SDL3.pm Public

    Perl Wrapper for the Simple DirectMedia Layer 3.0

    Perl 4

  2. Alien-SDL3.pm Alien-SDL3.pm Public

    Build and install SDL3 for Perl

    Perl 1

Repositories

Showing 7 of 7 repositories

Top languages

Loading…

Most used topics

Loading…