fixed url-generator
[sdlgit/SDL-Site.git] / pages / SDL-Tutorial.html-inc
CommitLineData
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.
47These 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,
50though. 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
55bbf7a2 56<a href="SDL-App.html">SDL::App</a> provides.</p>
162a0989 57<p>Of course, before you can get a surface, you need to initialize your video
58mode. SDL gives you several options, including whether to run in a window or
59take over the full screen, the size of the window, the bit depth of your
60colors, and whether to use hardware acceleration. For now, we'll build
61something 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
67ask for a windowed surface with 640x480x16 resolution:</p>
68<pre> use SDL::App;
69
70 my $app = SDL::App-&gt;new(
71 -width =&gt; 640,
72 -height =&gt; 480,
73 -depth =&gt; 16,
74 );
75
76</pre>
77<p>You can get more creative, especially if you use the <code>-title</code> and <code>-icon</code>
78attributes in a windowed application. Here's how to set the window title of
79the application to <code>My SDL Program</code>:</p>
80<pre> use SDL::App;
81
82 my $app = SDL::App-&gt;new(
83 -height =&gt; 640,
84 -width =&gt; 480,
85 -depth =&gt; 16,
86 -title =&gt; '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
91surface. That's a bit more complicated, but see the <code>-name</code> parameter to
92<code>SDL::Surface-</code>new()&gt; 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,
55bbf7a2 98it behaves much like <a href="SDL-Surface.html">SDL::Surface</a>. In particular, the all-important <code>blit</code>
99and <code>update</code> methods work. You'll need to create <a href="SDL-Rect.html">SDL::Rect</a> objects
162a0989 100representing sources of graphics to draw onto the <code>$app</code>'s surface, <code>blit</code>
101them there, then <code>update</code> the <code>$app</code>.</p>
102<p><strong>Note:</strong> &quot;blitting&quot; 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>
55bbf7a2 109 <dt><a href="SDL-Tutorial-Drawing.html">SDL::Tutorial::Drawing</a></dt>
162a0989 110 <dd>
111 <p>basic drawing with rectangles</p>
112 </dd>
55bbf7a2 113 <dt><a href="SDL-Tutorial-Animation.html">SDL::Tutorial::Animation</a></dt>
162a0989 114 <dd>
115 <p>basic rectangle animation</p>
116 </dd>
55bbf7a2 117 <dt><a href="SDL-Tutorial-Images.html">SDL::Tutorial::Images</a></dt>
162a0989 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, &lt;chromatic@wgz.org&gt;. </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
133distributed under the same terms as Perl itself, in the hope that it is useful
134but certainly under no guarantee.
135</p>
136
137</div>
138</div>