SDL - Simple DirectMedia Layer for Perl
Core
use SDL;
SDL_perl is a package of Perl modules that provide both functional and object oriented interfaces to the Simple DirectMedia Layer for Perl 5. This package takes some liberties with the SDL API, and attempts to adhere to the spirit of both the SDL and Perl. This document describes the low-level functional SDL Perl API. For the object oriented programming interface please see the documentation provided on a per-class basis.
The constants are not exported by default. You can export them by doing:
use SDL ':all';
or access them directly:
SDL::SDL_INIT_AUDIO;
or by choosing the export tags below:
Export tag: ':init'
SDL_INIT_AUDIO SDL_INIT_VIDEO SDL_INIT_CDROM SDL_INIT_EVERYTHING SDL_INIT_NOPARACHUTE SDL_INIT_JOYSTICK SDL_INIT_TIMER
As with the C language API, SDL Perl initializes the SDL environment with the SDL::init subroutine. This routine takes a mode flag constructed through the bitwise OR product of the SDL_INIT_* constants. The flags tell SDL::init which subsystems to initialize.
SDL::init
SDL_INIT_*
flags
SDL::init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
SDL::init returns 0 on success, or -1 on error.
0
-1
After SDL has been initialized with SDL::init you may initialize any uninitialized subsystems with SDL::init_subsystem. The flags tell SDL::init_subsystem which subsystems to initialize, and are taken in the same way as SDL::init.
SDL
SDL::init_subsystem
SDL::init_subsystem returns 0 on success, or -1 on error.
SDL::quit_subsystem allows you to shut down a subsystem that has been previously initialized by SDL::init or SDL::init_subsystem. The flags tell SDL::quit_subsystem which subsystems to shut down, and are taken in the same way as SDL::init.
SDL::quit_subsystem
SDL::quit_subsystem doesn't return any values.
SDL::quit Shuts down all SDL subsystems, unloads the dynamically linked library and frees the allocated resources.
SDL::quit
Note: This will be called automatically when Perl exits. You don't need to call this, except if you want to initialize SDL again after this.
SDL::quit doesn't return any values.
SDL::was_init allows you to see which SDL subsytems have been initialized. The flags tell SDL::was_init which subsystems to check, and are taken in the same way as SDL::init.
SDL::was_init
SDL::was_init returns a mask of the initialized subsystems it checks. If flags is 0 or SDL_INIT_EVERYTHING, a mask of all initialized subsystems will be returned (this does not include SDL_INIT_EVENTTHREAD or SDL_INIT_NOPARACHUTE).
SDL_INIT_EVERYTHING
SDL_INIT_EVENTTHREAD
SDL_INIT_NOPARACHUTE
use SDL ':all'; my $mask = SDL::was_init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); if($mask & SDL_INIT_AUDIO and $mask & SDL_INIT_JOYSTICK) { # Both subsystems are initialized! }
Returns a scalar value containing the last error message set by the SDL library (if any).
SDL::set_error_real sets the SDL error to a printf style formatted string.
SDL::set_error_real
printf
SDL::set_error_real doesn't return any values.
SDL::clear_error deletes all information about the last SDL error. This is useful if the error has been handled by the program.
SDL::clear_error
SDL::clear_error doesn't return any values.
Returns an SDL::Version object of the SDL library at compile-time.
SDL::Version
use SDL; use SDL::Version; my $v = SDL::version(); printf("got version: %d.%d.%d\n", $v->major, $v->minor, $v->patch);
SDL::linked_version works in the same way as SDL::version, but returns an SDL::Version object of the SDL library at link-time.
SDL::linked_version
SDL::version
Returns the number of milliseconds since SDL library initialization. This value wraps around if the program runs for more than 49.7 days
SDL::delay waits the specified number of milliseconds before returning. The actual delay may be longer than specified depending on the underlying OS.
SDL::delay
SDL::delay doesn't return anything.
# Delay for half a second SDL::delay(500);
magnet, kthakore, Blaizer
To install SDL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SDL
CPAN shell
perl -MCPAN -e shell install SDL
For more information on module installation, please visit the detailed CPAN module installation guide.