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