Updated site
[sdlgit/SDL-Site.git] / pages / SDL-Tutorial.html-inc
1 <div class="pod">
2 <!-- INDEX START -->
3 <h3 id="TOP">Index</h3>
4
5 <ul><li><a href="#NAME">NAME</a>
6 <ul><li><a href="#CATEGORY">CATEGORY</a></li>
7 </ul>
8 </li>
9 <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
10 <li><a href="#SDL_Manual">SDL Manual</a></li>
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>
18 <li><a href="#AUTHORS">AUTHORS</a></li>
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>
29 <h2 id="CATEGORY">CATEGORY</h2>
30 <div id="CATEGORY_CONTENT">
31 <p>Tutorials</p>
32
33 </div>
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
39         # to run this tutorial 
40         $ perl -MSDL::Tutorial -e 1
41
42 </pre>
43
44 </div>
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 
48 a complete tutorial for SDL. See <a href="http://search.cpan.org/perldoc?">http://search.cpan.org/perldoc?</a>.</p>
49
50 </div>
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.
54 These are the Perl 5 bindings.  You can find out more about SDL at
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>
56 <p>Creating an SDL application with Perl is easy.  You have to know a few basics,
57 though.  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
63 <a href="SDLx-App.html">SDLx::App</a> provides.</p>
64 <p>Of course, before you can get a surface, you need to initialize your video
65 mode.  SDL gives you several options, including whether to run in a window or
66 take over the full screen, the size of the window, the bit depth of your
67 colors, and whether to use hardware acceleration.  For now, we'll build
68 something really simple.</p>
69
70 </div>
71 <h2 id="Initialization">Initialization</h2>
72 <div id="Initialization_CONTENT">
73 <p>SDLx::App makes it easy to initialize video and create a surface.  Here's how to
74 ask for a windowed surface with 640x480x16 resolution:</p>
75 <pre>   use SDLx::App;
76
77         my $app = SDLx::App-&gt;new(
78                 width  =&gt; 640,
79                 height =&gt; 480,
80                 depth  =&gt; 16,
81         );
82
83 </pre>
84 <p>You can get more creative, especially if you use the <code>title</code> and <code>icon</code>
85 attributes in a windowed application.  Here's how to set the window title of
86 the application to <code>My SDL Program</code>:</p>
87 <pre>   use SDLx::App;
88
89         my $app = SDLx::App-&gt;new(
90                 height =&gt; 640,
91                 width  =&gt; 480,
92                 depth  =&gt; 16,
93                 title  =&gt; 'My SDL Program',
94         );
95
96 </pre>
97 <p>Setting an icon is a little more involved -- you have to load an image onto a
98 surface.  That's a bit more complicated, but see the <code>name</code> parameter to
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,
105 it behaves much like <a href="SDL-Surface.html">SDL::Surface</a>.  In particular, the all-important <code>blit</code>
106 and <code>update</code> methods work.  You'll need to create <a href="SDL-Rect.html">SDL::Rect</a> objects
107 representing sources of graphics to draw onto the <code>$app</code>'s surface, <code>blit</code>
108 them 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>
116         <dt><a href="SDL-Tutorial-Animation.html">SDL::Tutorial::Animation</a></dt>
117         <dd>
118                 <p>basic rectangle drawing and animation</p>
119         </dd>
120         <dt><a href="SDL-Tutorial-LunarLander.html">SDL::Tutorial::LunarLander</a></dt>
121         <dd>
122                 <p>basic image loading and animation</p>
123         </dd>
124 </dl>
125
126 </div>
127 <h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
128 <div id="AUTHORS_CONTENT">
129 <p>chromatic, &lt;chromatic@wgz.org&gt;. </p>
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>
131
132 </div>
133 <h1 id="COPYRIGHT">COPYRIGHT</h1><p><a href="#TOP" class="toplink">Top</a></p>
134 <div id="COPYRIGHT_CONTENT">
135 <p>Copyright (c) 2003 - 2004, chromatic. 2009 - 2010, kthakore.  All rights reserved.  This module is
136 distributed under the same terms as Perl itself, in the hope that it is useful
137 but certainly under no guarantee.
138 </p>
139
140 </div>
141 </div>