PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/pods/SDL/Tutorial.pod

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