Updated docs
[sdlgit/SDL-Site.git] / pages / SDL-Surface.html-inc
CommitLineData
162a0989 1<div class="pod">
2<!-- INDEX START -->
3<h3 id="TOP">Index</h3>
4
c5cfaf97 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>
5da56497 9<li><a href="#CONSTANTS">CONSTANTS</a></li>
162a0989 10<li><a href="#METHODS">METHODS</a>
801213bd 11<ul><li><a href="#new">new</a></li>
12<li><a href="#new_from">new_from</a></li>
162a0989 13<li><a href="#w">w</a></li>
14<li><a href="#h">h</a></li>
0d76f1af 15<li><a href="#format">format</a></li>
16<li><a href="#pitch">pitch</a></li>
0d76f1af 17</ul>
18</li>
19<li><a href="#Direct_Write_to_Surface_Pixel">Direct Write to Surface Pixel</a>
f373167e 20<ul><li><a href="#get_pixel">get_pixel</a></li>
801213bd 21<li><a href="#set_pixels">set_pixels</a></li>
0d76f1af 22<li><a href="#get_pixels_ptr">get_pixels_ptr</a></li>
162a0989 23</ul>
24</li>
25<li><a href="#SEE_ALSO">SEE ALSO</a>
26</li>
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">
801213bd 32<p>SDL::Surface - Graphic surface structure</p>
162a0989 33
34</div>
c5cfaf97 35<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
bfdd9c2e 36<div id="CATEGORY_CONTENT">
37<p>Core, Video, Structure</p>
38
bfdd9c2e 39</div>
162a0989 40<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
41<div id="SYNOPSIS_CONTENT">
801213bd 42<pre> use SDL;
43 use SDL::Video;
44 use SDL::Surface;
162a0989 45
801213bd 46 # Create the main surface (display)
47 SDL::init(SDL_INIT_VIDEO);
48 my $display = SDL::Video::set_video_mode(640, 480, 16, SDL_SWSURFACE);
49
50 # Create other surfaces attached to the $display.
51 my $surface = SDL::Surface-&gt;new(SDL_ASYNCBLIT | SDL_HWSURFACE, 640, 480, 16, 0, 0, 0, 0);
52 my $surface2 = SDL::Surface-&gt;new_from($surface, 100, 100, 8, 0, 0, 0, 0);
162a0989 53
54</pre>
55
56</div>
57<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
58<div id="DESCRIPTION_CONTENT">
59<p>An <code>SDL_Surface</code> defines a surfaceangular area of pixels.</p>
60
61</div>
5da56497 62<h1 id="CONSTANTS">CONSTANTS</h1><p><a href="#TOP" class="toplink">Top</a></p>
63<div id="CONSTANTS_CONTENT">
801213bd 64<p>The constants for SDL::Surface belong to SDL::Video, under the export tag of <code>':surface'</code>.</p>
0d76f1af 65<dl>
0d76f1af 66 <dt>SDL_ASYNCBLIT</dt>
67 <dd>
68 <p>Use asynchronous blit if possible</p>
69 </dd>
0d76f1af 70 <dt>SDL_SWSURFACE</dt>
71 <dd>
801213bd 72 <p>Store in system memory</p>
0d76f1af 73 </dd>
5da56497 74 <dt>SDL_HWSURFACE</dt>
0d76f1af 75 <dd>
801213bd 76 <p>Store in video memory</p>
0d76f1af 77 </dd>
78</dl>
162a0989 79
162a0989 80</div>
801213bd 81<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
82<div id="METHODS_CONTENT">
83
84</div>
85<h2 id="new">new</h2>
86<div id="new_CONTENT">
87<pre> my $surface = SDL::Surface-&gt;new(
88 $flags, $width, $height, $depth, $Rmask, $Gmask, $Bmask, $Amask
89 );
90
91</pre>
92<p>The constructor creates a new surface with the specified parameter values.</p>
93<p>The four mask values are the bits that the channel will ignore.
94For example, an Rmask of <code>0xFF</code> will ignore that channel completely, making everything on the surface more green/blue.</p>
95
96</div>
97<h2 id="new_from">new_from</h2>
98<div id="new_from_CONTENT">
99<pre> my $surface = SDL::Surface-&gt;new_from(
100 $surface, $width, $height, $depth, $Rmask, $Gmask, $Bmask, $Amask
101 );
102
103</pre>
104<p>The constructor creates a new surface with the specified parameter values.
105The flags are taken from the specified <code>$surface</code>.</p>
106
107</div>
162a0989 108<h2 id="w">w</h2>
109<div id="w_CONTENT">
801213bd 110<pre> my $w = $surface-&gt;w;
162a0989 111
112</pre>
801213bd 113<p>Returns the width of the surface.
114SDL::Surface width is defined at construction so this is read-only.</p>
162a0989 115
116</div>
117<h2 id="h">h</h2>
118<div id="h_CONTENT">
801213bd 119<pre> my $h = $surface-&gt;h;
162a0989 120
121</pre>
801213bd 122<p>Returns the height of the surface.
123SDL::Surface height is defined at construction so this is read-only.</p>
162a0989 124
125</div>
0d76f1af 126<h2 id="format">format</h2>
127<div id="format_CONTENT">
0d76f1af 128<pre> my $format = $surface-&gt;format;
129
130</pre>
801213bd 131<p>The format of the pixels stored in the surface.
132See <a href="SDL-PixelFormat.html">SDL::PixelFormat</a></p>
0d76f1af 133
134</div>
135<h2 id="pitch">pitch</h2>
136<div id="pitch_CONTENT">
137<pre> my $pitch = $surface-&gt;pitch;
138
139</pre>
801213bd 140<p>The scanline length in bytes.</p>
0d76f1af 141
142</div>
143<h1 id="Direct_Write_to_Surface_Pixel">Direct Write to Surface Pixel</h1><p><a href="#TOP" class="toplink">Top</a></p>
144<div id="Direct_Write_to_Surface_Pixel_CONTEN">
801213bd 145<p><strong>Disclaimer:</strong> The following methods can be very slow, making them suitable for creating surfaces, but not for animations</p>
0d76f1af 146
147</div>
f373167e 148<h2 id="get_pixel">get_pixel</h2>
149<div id="get_pixel_CONTENT">
801213bd 150<pre> my $pixel = $surface-&gt;get_pixel( $offset )
0d76f1af 151
152</pre>
801213bd 153<p>Returns the pixel value for the given <code>$offset</code>.
154The pixel value depends on current pixel format.</p>
155<p><strong>Note:</strong> For surfaces with a palette (1 byte per pixel) the palette index is returned instead of color values.</p>
0d76f1af 156
157</div>
158<h2 id="set_pixels">set_pixels</h2>
159<div id="set_pixels_CONTENT">
160<pre> $surface-&gt;set_pixels( $offset, $value );
161
162</pre>
801213bd 163<p>Sets the pixel <code>$value</code> to the given <code>$offset</code>.
164The pixel value must fit the pixel format of the surface.</p>
f373167e 165<p><strong>Note</strong>: For surfaces with a palette (1 byte per pixel) the palette index must be passed instead of color values.</p>
801213bd 166<p>Example:</p>
167<pre> sub putpixel {
168 my ($x, $y, $color) = @_;
169 $display-&gt;set_pixels( $x + $y * $display-&gt;w, $color);
f373167e 170 }
0d76f1af 171
172</pre>
801213bd 173<p>See also <cite>examples/pixel_operations/sols/ch02.pl</cite>!</p>
0d76f1af 174
175</div>
176<h2 id="get_pixels_ptr">get_pixels_ptr</h2>
177<div id="get_pixels_ptr_CONTENT">
801213bd 178<pre> my $ptr = $surface-&gt;get_pixels_ptr;
0d76f1af 179
180</pre>
801213bd 181<p>Returns a reference to the surface's pixels.</p>
0d76f1af 182
183</div>
162a0989 184<h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
185<div id="SEE_ALSO_CONTENT">
55bbf7a2 186<p><a href="SDL.html">SDL</a>, <a href="SDL-PixelFormat.html">SDL::PixelFormat</a>, <a href="SDL-Video.html">SDL::Video</a>, <a href="SDL-Rect.html">SDL::Rect</a></p>
162a0989 187
188</div>
189</div>