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