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