1SDL::Tutorial(3) User Contributed Perl Documentation SDL::Tutorial(3)
2
3
4
6 SDL::Tutorial - introduction to Perl SDL
7
9 # to read this tutorial
10 $ perldoc SDL::Tutorial
11
12 # to create a bare-bones SDL app based on this tutorial
13 $ perl -MSDL::Tutorial=basic_app.pl -e 1
14
16 SDL, the Simple DirectMedia Layer, is a cross-platform multimedia
17 library. These are the Perl 5 bindings. You can find out more about
18 SDL at <http://www.libsdl.org/>.
19
20 Creating an SDL application with Perl is easy. You have to know a few
21 basics, though. Here's how to get up and running as quickly as possi‐
22 ble.
23
24 Surfaces
25
26 All graphics in SDL live on a surface. You'll need at least one.
27 That's what SDL::App provides.
28
29 Of course, before you can get a surface, you need to initialize your
30 video mode. SDL gives you several options, including whether to run in
31 a window or take over the full screen, the size of the window, the bit
32 depth of your colors, and whether to use hardware acceleration. For
33 now, we'll build something really simple.
34
35 Initialization
36
37 SDL::App makes it easy to initialize video and create a surface.
38 Here's how to ask for a windowed surface with 640x480x16 resolution:
39
40 use SDL::App;
41
42 my $app = SDL::App->new(
43 -width => 640,
44 -height => 480,
45 -depth => 16,
46 );
47
48 You can get more creative, especially if you use the "-title" and
49 "-icon" attributes in a windowed application. Here's how to set the
50 window title of the application to "My SDL Program":
51
52 use SDL::App;
53
54 my $app = SDL::App->new(
55 -height => 640,
56 -width => 480,
57 -depth => 16,
58 -title => 'My SDL Program',
59 );
60
61 Setting an icon is a little more involved -- you have to load an image
62 onto a surface. That's a bit more complicated, but see the "-name"
63 parameter to "SDL::Surface-"new()> if you want to skip ahead.
64
65 Working With The App
66
67 Since $app from the code above is just an SDL surface with some extra
68 sugar, it behaves much like SDL::Surface. In particular, the all-
69 important "blit" and "update" methods work. You'll need to create
70 SDL::Rect objects representing sources of graphics to draw onto the
71 $app's surface, "blit" them there, then "update" the $app.
72
73 Note: "blitting" is copying a chunk of memory from one place to
74 another.
75
76 That, however, is another tutorial.
77
79 SDL::Tutorial::Drawing
80 basic drawing with rectangles
81
82 SDL::Tutorial::Animation
83 basic rectangle animation
84
85 SDL::Tutorial::Images
86 image loading and animation
87
89 chromatic, <chromatic@wgz.org>.
90
91 Written for and maintained by the Perl SDL project,
92 <http://sdl.perl.org/>.
93
95 Copyright (c) 2003 - 2004, chromatic. All rights reserved. This mod‐
96 ule is distributed under the same terms as Perl itself, in the hope
97 that it is useful but certainly under no guarantee.
98
99
100
101perl v5.8.8 2006-08-28 SDL::Tutorial(3)