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