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