5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
7 # ------------------------------------------------------------------------------
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 # ------------------------------------------------------------------------------
25 # Please feel free to send questions, suggestions or improvements to:
31 package SDL::Tutorial;
37 # change these values as necessary
38 my $title = 'My SDL App';
39 my ($width, $height, $depth) = ( 640, 480, 16 );
41 my $app = SDL::App->new(
48 # your code here; remove the next line
57 SDL::Tutorial - introduction to Perl SDL
61 # to read this tutorial
62 $ perldoc SDL::Tutorial
64 # to create a bare-bones SDL app based on this tutorial
65 $ perl -MSDL::Tutorial -e 1
69 SDL, the Simple DirectMedia Layer, is a cross-platform multimedia library.
70 These are the Perl 5 bindings. You can find out more about SDL at
71 L<http://www.libsdl.org/>.
73 Creating an SDL application with Perl is easy. You have to know a few basics,
74 though. Here's how to get up and running as quickly as possible.
78 All graphics in SDL live on a surface. You'll need at least one. That's what
81 Of course, before you can get a surface, you need to initialize your video
82 mode. SDL gives you several options, including whether to run in a window or
83 take over the full screen, the size of the window, the bit depth of your
84 colors, and whether to use hardware acceleration. For now, we'll build
85 something really simple.
89 SDL::App makes it easy to initialize video and create a surface. Here's how to
90 ask for a windowed surface with 640x480x16 resolution:
94 my $app = SDL::App->new(
100 You can get more creative, especially if you use the C<-title> and C<-icon>
101 attributes in a windowed application. Here's how to set the window title of
102 the application to C<My SDL Program>:
106 my $app = SDL::App->new(
110 -title => 'My SDL Program',
113 Setting an icon is a little more involved -- you have to load an image onto a
114 surface. That's a bit more complicated, but see the C<-name> parameter to
115 C<SDL::Surface->new()> if you want to skip ahead.
117 =head2 Working With The App
119 Since C<$app> from the code above is just an SDL surface with some extra sugar,
120 it behaves much like L<SDL::Surface>. In particular, the all-important C<blit>
121 and C<update> methods work. You'll need to create L<SDL::Rect> objects
122 representing sources of graphics to draw onto the C<$app>'s surface, C<blit>
123 them there, then C<update> the C<$app>.
125 B<Note:> "blitting" is copying a chunk of memory from one place to another.
127 That, however, is another tutorial.
133 =item L<SDL::Tutorial::Drawing>
135 basic drawing with rectangles
137 =item L<SDL::Tutorial::Animation>
139 basic rectangle animation
141 =item L<SDL::Tutorial::Images>
143 image loading and animation
149 chromatic, E<lt>chromatic@wgz.orgE<gt>.
151 Written for and maintained by the Perl SDL project, L<http://sdl.perl.org/>.
155 Copyright (c) 2003 - 2004, chromatic. All rights reserved. This module is
156 distributed under the same terms as Perl itself, in the hope that it is useful
157 but certainly under no guarantee.