Merge branch 'master' of git.shadowcat.co.uk:SDL-Site
[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>
c7e8d3c6 17<li><a href="#AUTHORS">AUTHORS</a></li>
162a0989 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
148a0b32 38 # to run this tutorial
162a0989 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
148a0b32 48<a href="http://www.libsdl.org/">http://www.libsdl.org/</a>. You can find out more about SDL perl at <a href="http://sdl.perl.org">http://sdl.perl.org</a>.</p>
162a0989 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
1dbe1697 56<a href="SDLx-App.html">SDLx::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">
ca0a3441 66<p>SDLx::App makes it easy to initialize video and create a surface. Here's how to
162a0989 67ask for a windowed surface with 640x480x16 resolution:</p>
ca0a3441 68<pre> use SDLx::App;
162a0989 69
ca0a3441 70 my $app = SDLx::App-&gt;new(
505f308d 71 width =&gt; 640,
72 height =&gt; 480,
73 depth =&gt; 16,
162a0989 74 );
75
76</pre>
505f308d 77<p>You can get more creative, especially if you use the <code>title</code> and <code>icon</code>
162a0989 78attributes in a windowed application. Here's how to set the window title of
79the application to <code>My SDL Program</code>:</p>
ca0a3441 80<pre> use SDLx::App;
162a0989 81
ca0a3441 82 my $app = SDLx::App-&gt;new(
505f308d 83 height =&gt; 640,
84 width =&gt; 480,
85 depth =&gt; 16,
86 title =&gt; 'My SDL Program',
162a0989 87 );
88
89</pre>
90<p>Setting an icon is a little more involved -- you have to load an image onto a
505f308d 91surface. That's a bit more complicated, but see the <code>name</code> parameter to
162a0989 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>
1f5d8082 109 <dt><a href="SDL-Animation.html">SDL::Animation</a></dt>
162a0989 110 <dd>
1f5d8082 111 <p>basic rectangle drawing and animation</p>
162a0989 112 </dd>
1f5d8082 113 <dt><a href="SDL-Tutorial-LunarLander.html">SDL::Tutorial::LunarLander</a></dt>
162a0989 114 <dd>
1f5d8082 115 <p>basic image loading and animation</p>
162a0989 116 </dd>
117</dl>
118
119</div>
c7e8d3c6 120<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
121<div id="AUTHORS_CONTENT">
1f5d8082 122<p>chromatic, &lt;chromatic@wgz.org&gt;. </p>
1dbe1697 123<p>Written for and maintained by the Perl SDL project, <a href="http://sdl.perl.org/">http://sdl.perl.org/</a>. See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a> for details.</p>
162a0989 124
125</div>
126<h1 id="COPYRIGHT">COPYRIGHT</h1><p><a href="#TOP" class="toplink">Top</a></p>
127<div id="COPYRIGHT_CONTENT">
1f5d8082 128<p>Copyright (c) 2003 - 2004, chromatic. 2009 - 2010, kthakore. All rights reserved. This module is
162a0989 129distributed under the same terms as Perl itself, in the hope that it is useful
130but certainly under no guarantee.
131</p>
132
133</div>
134</div>