Updated docs
[sdlgit/SDL-Site.git] / pages / SDL.html-inc
CommitLineData
162a0989 1<div class="pod">
2<!-- INDEX START -->
3<h3 id="TOP">Index</h3>
4
05c66c33 5<ul><li><a href="#NAME">NAME</a></li>
6<li><a href="#CATEGORY">CATEGORY</a></li>
162a0989 7<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
8<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
05c66c33 9<li><a href="#CONSTANTS">CONSTANTS</a></li>
10<li><a href="#METHODS">METHODS</a>
801213bd 11<ul><li><a href="#init">init</a></li>
12<li><a href="#init_subsystem">init_subsystem</a></li>
13<li><a href="#quit_subsystem">quit_subsystem</a></li>
14<li><a href="#quit">quit</a></li>
15<li><a href="#was_init">was_init</a></li>
16<li><a href="#get_error">get_error</a></li>
17<li><a href="#set_error_real">set_error_real</a></li>
18<li><a href="#clear_error">clear_error</a></li>
19<li><a href="#version">version</a></li>
20<li><a href="#linked_version">linked_version</a></li>
21<li><a href="#get_ticks">get_ticks</a></li>
22<li><a href="#delay">delay</a></li>
162a0989 23</ul>
24</li>
801213bd 25<li><a href="#AUTHOR">AUTHOR</a>
ecabf8b7 26</li>
162a0989 27</ul><hr />
28<!-- INDEX END -->
29
30<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
31<div id="NAME_CONTENT">
879e3e79 32<p>SDL - Simple DirectMedia Layer for Perl</p>
162a0989 33
34</div>
05c66c33 35<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
bfdd9c2e 36<div id="CATEGORY_CONTENT">
37<p>Core</p>
38
39</div>
162a0989 40<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
41<div id="SYNOPSIS_CONTENT">
05c66c33 42<pre> use SDL;
162a0989 43
44</pre>
45
46</div>
47<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
48<div id="DESCRIPTION_CONTENT">
05c66c33 49<p>SDL_perl is a package of Perl modules that provide both functional and object oriented interfaces to the Simple DirectMedia Layer for Perl 5.
50This package takes some liberties with the SDL API, and attempts to adhere to the spirit of both the SDL and Perl.
51This document describes the low-level functional SDL Perl API.
52For the object oriented programming interface please see the documentation provided on a per-class basis.</p>
162a0989 53
54</div>
05c66c33 55<h1 id="CONSTANTS">CONSTANTS</h1><p><a href="#TOP" class="toplink">Top</a></p>
56<div id="CONSTANTS_CONTENT">
57<p>The constants are not exported by default. You can export them by doing:</p>
30652763 58<pre> use SDL ':all';
59
60</pre>
61<p>or access them directly:</p>
62<pre> SDL::SDL_INIT_AUDIO;
63
64</pre>
9b105a17 65<p>or by choosing the export tags below:</p>
66<p>Export tag: ':init'</p>
05c66c33 67<pre> SDL_INIT_AUDIO
68 SDL_INIT_VIDEO
69 SDL_INIT_CDROM
70 SDL_INIT_EVERYTHING
71 SDL_INIT_NOPARACHUTE
72 SDL_INIT_JOYSTICK
73 SDL_INIT_TIMER
74
75</pre>
76
77</div>
78<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
79<div id="METHODS_CONTENT">
80
81</div>
801213bd 82<h2 id="init">init</h2>
83<div id="init_CONTENT">
84<pre> SDL::init( $flags );
85
86</pre>
05c66c33 87<p>As with the C language API, SDL Perl initializes the SDL environment with the <code>SDL::init</code> subroutine.
88This routine takes a mode flag constructed through the bitwise OR product of the <code>SDL_INIT_*</code> constants.
801213bd 89The <code>$flags</code> tell <code>SDL::init</code> which subsystems to initialize.</p>
05c66c33 90<pre> SDL::init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
91
92</pre>
93<p><code>SDL::init</code> returns <code>0</code> on success, or <code>-1</code> on error.</p>
162a0989 94
95</div>
801213bd 96<h2 id="init_subsystem">init_subsystem</h2>
97<div id="init_subsystem_CONTENT">
98<pre> SDL::init_subsystem( $flags );
99
100</pre>
101<p>After SDL has been initialized with <code>SDL::init</code> you may initialize any uninitialized subsystems with <code>SDL::init_subsystem</code>.
102The <code>$flags</code> tell <code>SDL::init_subsystem</code> which subsystems to initialize, and are taken in the same way as <code>SDL::init</code>.</p>
05c66c33 103<p><code>SDL::init_subsystem</code> returns <code>0</code> on success, or <code>-1</code> on error.</p>
162a0989 104
105</div>
801213bd 106<h2 id="quit_subsystem">quit_subsystem</h2>
107<div id="quit_subsystem_CONTENT">
108<pre> SDL::quit_subsystem( $flags );
109
110</pre>
05c66c33 111<p><code>SDL::quit_subsystem</code> allows you to shut down a subsystem that has been previously initialized by <code>SDL::init</code> or <code>SDL::init_subsystem</code>.
801213bd 112The <code>$flags</code> tell <code>SDL::quit_subsystem</code> which subsystems to shut down, and are taken in the same way as <code>SDL::init</code>.</p>
05c66c33 113<p><code>SDL::quit_subsystem</code> doesn't return any values.</p>
162a0989 114
115</div>
801213bd 116<h2 id="quit">quit</h2>
162a0989 117<div id="quit_CONTENT">
801213bd 118<pre> SDL::quit;
119
120</pre>
05c66c33 121<p><code>SDL::quit</code> Shuts down all SDL subsystems, unloads the dynamically linked library and frees the allocated resources.</p>
122<p><strong>Note:</strong> This will be called automatically when Perl exits. You don't need to call this, except if you want to initialize SDL again after this.</p>
123<p><code>SDL::quit</code> doesn't return any values.</p>
162a0989 124
125</div>
801213bd 126<h2 id="was_init">was_init</h2>
127<div id="was_init_CONTENT">
128<pre> my $flags = SDL::was_init( $flags );
129
130</pre>
05c66c33 131<p><code>SDL::was_init</code> allows you to see which SDL subsytems have been initialized.
801213bd 132The <code>$flags</code> tell <code>SDL::was_init</code> which subsystems to check, and are taken in the same way as <code>SDL::init</code>.</p>
05c66c33 133<p><code>SDL::was_init</code> returns a mask of the initialized subsystems it checks.
801213bd 134If <code>$flags</code> is <code>0</code> or <code>SDL_INIT_EVERYTHING</code>, a mask of all initialized subsystems will be returned (this does not include <code>SDL_INIT_EVENTTHREAD</code> or <code>SDL_INIT_NOPARACHUTE</code>).</p>
05c66c33 135<pre> use SDL ':all';
136
137 my $mask = SDL::was_init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
138 if($mask &amp; SDL_INIT_AUDIO and $mask &amp; SDL_INIT_JOYSTICK) {
139 # Both subsystems are initialized!
140 }
141
142</pre>
162a0989 143
162a0989 144</div>
801213bd 145<h2 id="get_error">get_error</h2>
162a0989 146<div id="get_error_CONTENT">
801213bd 147<pre> my $error = SDL::get_error;
148
149</pre>
05c66c33 150<p>Returns a scalar value containing the last error message set by the SDL library (if any).</p>
162a0989 151
152</div>
801213bd 153<h2 id="set_error_real">set_error_real</h2>
154<div id="set_error_real_CONTENT">
155<pre> SDL::set_error_real( $printf_format, @values )
156
157</pre>
05c66c33 158<p><code>SDL::set_error_real</code> sets the SDL error to a <code>printf</code> style formatted string.</p>
159<p><code>SDL::set_error_real</code> doesn't return any values.</p>
162a0989 160
161</div>
801213bd 162<h2 id="clear_error">clear_error</h2>
096d8dc8 163<div id="clear_error_CONTENT">
801213bd 164<pre> SDL::clear_error;
165
166</pre>
05c66c33 167<p><code>SDL::clear_error</code> deletes all information about the last SDL error.
168This is useful if the error has been handled by the program.</p>
169<p><code>SDL::clear_error</code> doesn't return any values.</p>
162a0989 170
171</div>
801213bd 172<h2 id="version">version</h2>
9b105a17 173<div id="version_CONTENT">
801213bd 174<pre> my $version = SDL::version;
175
176</pre>
05c66c33 177<p>Returns an <code>SDL::Version</code> object of the SDL library at compile-time.</p>
9b105a17 178<pre> use SDL;
179 use SDL::Version;
180
801213bd 181 my $v = SDL::version;
9b105a17 182 printf(&quot;got version: %d.%d.%d\n&quot;, $v-&gt;major, $v-&gt;minor, $v-&gt;patch);
162a0989 183
9b105a17 184</pre>
162a0989 185
186</div>
801213bd 187<h2 id="linked_version">linked_version</h2>
162a0989 188<div id="linked_version_CONTENT">
05c66c33 189<p><code>SDL::linked_version</code> works in the same way as <code>SDL::version</code>, but returns an <code>SDL::Version</code> object of the SDL library at link-time.</p>
162a0989 190
191</div>
801213bd 192<h2 id="get_ticks">get_ticks</h2>
05c66c33 193<div id="get_ticks_CONTENT">
801213bd 194<pre> my $ticks = SDL::get_ticks;
195
196</pre>
05c66c33 197<p>Returns the number of milliseconds since SDL library initialization.
198This value wraps around if the program runs for more than 49.7 days</p>
162a0989 199
200</div>
801213bd 201<h2 id="delay">delay</h2>
202<div id="delay_CONTENT">
203<pre> SDL::delay( $ms );
204
205</pre>
05c66c33 206<p><code>SDL::delay</code> waits the specified number of milliseconds before returning.
207The actual delay may be longer than specified depending on the underlying OS.</p>
208<p><code>SDL::delay</code> doesn't return anything.</p>
209<pre> # Delay for half a second
210 SDL::delay(500);
9b105a17 211
212</pre>
162a0989 213
ecabf8b7 214</div>
801213bd 215<h1 id="AUTHOR">AUTHOR</h1><p><a href="#TOP" class="toplink">Top</a></p>
216<div id="AUTHOR_CONTENT">
05c66c33 217<p>magnet, kthakore, Blaizer</p>
162a0989 218
219</div>
220</div>