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