Simple DirectMedia Layer (a.k.a libsdl) is a cross-platform C library that provides access to several input and output devices. Most popularly it is used for its access to the 2D video framebuffer and inputs for games.
In addition to the core library there are several other libraries that provide many features such as Text, Mixers, Images and GFX.
SDL Perl binds several of these libraries as closely as possible in the SDL::*
namespace. Moreover SDL Perl provides several high level libraries in the SDLx::*
namespace.
The main purpose of the SDLx::*
layer is to smooth out the drudgery from the SDL::*
layer. For example drawing a rectangle involves the following work.
Don't worry about understanding the code at this moment. Just compare the two code lisitings below.
use SDL;
use SDL::Video;
use SDL::Surface;
use SDL::Rect;
# the size of the window box or the screen resolution if fullscreen
my $screen_width = 800;
my $screen_height = 600;
SDL::init(SDL_INIT_VIDEO);
# setting video mode
my $screen_surface = SDL::Video::set_video_mode($screen_width,
$screen_height,
32,
SDL_ANYFORMAT);
# drawing a rectangle with the blue color
my $mapped_color = SDL::Video::map_RGB($screen_surface->format(), 0, 0, 255);
SDL::Video::fill_rect($screen_surface,
SDL::Rect->new($screen_width / 4, $screen_height / 4,
$screen_width / 2, $screen_height / 2),
$mapped_color);
# update an area on the screen so its visible
SDL::Video::update_rect($screen_surface, 0, 0, $screen_width, $screen_height);
sleep(5); # just to have time to see it
SDL::quit();
While drawing a blue rectangle in the SDLx::*
layer is as simple as:
use strict;
use warnings;
use SDL;
use SDLx::App;
my $app = SDLx::App->new( width=> 800, height => 600 );
$app->draw_rect([ $app->width/4, $app->height / 4, $app->width /2, $app->height / 2 ], [0,0,255,255] );
$app->update();
sleep(5);
A secondary purpose of the SDLx::*
is to add addtional features for users, such as Layers, Game Loop handling and more.
This book is written for new users of SDL Perl who have some experience with Perl, but not much experience with SDL. It is not necessary for the audience to be aware of SDL internals, as this book covers most areas as it goes.
This book will be formated into chapters that progressively increase in complexity. However each chapter can be treated as a separate tutorial to jump to and learn.
Each chapter will have a specific task (e.g. Making Pong), which we will work towards. The source for each chapter will be broken up and explained. Sources and data files will be provided on http://sdl.perl.org.
Finally the chapters will end with an exercise the reader can try out.
This book is intended to introduce game development to Perl programmers and at the same time introduce Modern Perl through game development. The book will aim to provide simple to intermediate examples and provide suggestions for more advanced endeavours.
Depending on your platform you may need some dependencies. Then we can do a final CPAN install.
Alien::SDL
will install binaries for 32bit and 64bit so there is no need to compile anything.
Fink has packages for SDL Perl available. However Pango is not currently supported.
Alien::SDL
will compile SDL dependencies from scratch with no problems as long some prerequisites are installed. libfreetype6
, libX11
, libvorbis
, libogg
and libpng
headers will suffice for most examples in this book.
You can use your package maintainers packages:
sudo apt-get install libsdl-net1.2-dev libsdl-mixer1.2-dev \
libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev \
libsdl-gfx1.2-dev libsdl-pango-dev
To compile from scratch some Header Packages are required.
sudo apt-get install build-essential xorg-dev libx11-dev \
libpango1.0-dev libfreetype6-dev libvorbis-dev libpng12-dev \
libogg-dev
sudo cpan SDL
For most platforms a CPAN install will suffice. Supported and tested platforms are displayed at http://pass.cpantesters.org/distro/S/SDL.html.
Hopefully this book shows you areas where SDL Perl can be improved, or you may need help with some issues. Please contact us with one of the following methods:
SDL Perl's homepage is at http://sdl.perl.org/.
The channel #sdl
on irc.perl.org
is very active and a great resource for help and getting involved.
If you need help with SDL Perl, send an to sdl-devel@perl.org
.
The code examples in this books are provided on http://github.com/PerlGameDev/SDL_Manual/tree/master/code_listings/ .
Perl community on #sdl
and #perl
.
Hey! The above document had some coding errors, which are explained below:
- Around line 1:
-
Unknown directive: =head0
- Around line 26:
-
=end sidebar without matching =begin. (Stack: [empty])
- Around line 142:
-
Deleting unknown formatting code U<>
- Around line 151:
-
Deleting unknown formatting code U<>
- Around line 163:
-
Deleting unknown formatting code U<>