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