3 <h3 id="TOP">Index</h3>
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#CATEGORY">CATEGORY</a></li>
7 <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
8 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
9 <li><a href="#CONSTANTS">CONSTANTS</a></li>
10 <li><a href="#METHODS">METHODS</a>
11 <ul><li><a href="#new_flags_width_height_depth_Rmask_G">new ( flags, width, height, depth, Rmask, Gmask, Bmask, Amask )</a></li>
12 <li><a href="#new_from_surface_width_height_depth_">new_from ( surface, width, height, depth, Rmask, Gmask, Bmask, Amask )</a>
13 <ul><li><a href="#Construtor_Parameters">Construtor Parameters</a>
14 <ul><li><a href="#flags">flags</a></li>
19 <li><a href="#w">w</a></li>
20 <li><a href="#h">h</a></li>
21 <li><a href="#format">format</a></li>
22 <li><a href="#pitch">pitch</a></li>
23 <li><a href="#clip_rect">clip_rect</a></li>
26 <li><a href="#Direct_Write_to_Surface_Pixel">Direct Write to Surface Pixel</a>
27 <ul><li><a href="#get_pixels">get_pixels</a></li>
28 <li><a href="#set_pixels">set_pixels</a>
29 <ul><li><a href="#Usage">Usage</a></li>
32 <li><a href="#get_pixels_ptr">get_pixels_ptr</a></li>
35 <li><a href="#SEE_ALSO">SEE ALSO</a>
40 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
41 <div id="NAME_CONTENT">
42 <p>SDL::Surface - Graphic surface structure.</p>
45 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
46 <div id="CATEGORY_CONTENT">
47 <p>Core, Video, Structure</p>
50 <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
51 <div id="SYNOPSIS_CONTENT">
52 <p>The main surface (display) is provided by <a href="/SDL-Video.html#set_video_mode">SDL::Video::set_video_mode</a>.
53 use SDL; #provides flags & constants
54 use SDL::Video; #provides access to set_video_mode
55 use SDL::Surface; #provides access to SDL_Surface struct internals</p>
56 <pre> SDL::init(SDL_INIT_VIDEO);
57 my $display = SDL::Video::set_video_mode();
60 <p>All surfaces constructed from now on are attached to the $display. There are two constructors available to do this.</p>
61 <pre> my $surface = SDL::Surface->new ( ... );
62 my $surface2 = SDL::Surface->new_from ( surface, ... );
67 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
68 <div id="DESCRIPTION_CONTENT">
69 <p>An <code>SDL_Surface</code> defines a surfaceangular area of pixels.</p>
72 <h1 id="CONSTANTS">CONSTANTS</h1><p><a href="#TOP" class="toplink">Top</a></p>
73 <div id="CONSTANTS_CONTENT">
74 <p>The constants are not exported by default. You can export them into your namespace by doing:</p>
75 <pre> use SDL::Video ':surface';
79 <pre> use SDL::Video ':all';
82 <p>or access them directly:</p>
83 <pre> SDL::Video::SDL_SWSURFACE;
86 <p>Available constants: see <a href="#flags">flags</a></p>
89 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
90 <div id="METHODS_CONTENT">
93 <h2 id="new_flags_width_height_depth_Rmask_G">new ( flags, width, height, depth, Rmask, Gmask, Bmask, Amask )</h2>
94 <div id="new_flags_width_height_depth_Rmask_G-2">
95 <p>The constructor creates a new surface with the specified parameter values.</p>
96 <pre> my $surface = SDL::Surface->new( ... );
101 <h2 id="new_from_surface_width_height_depth_">new_from ( surface, width, height, depth, Rmask, Gmask, Bmask, Amask )</h2>
102 <div id="new_from_surface_width_height_depth_-2">
103 <p>The constructor creates a new surface with the specified parameter values. </p>
104 <pre> my $surface = SDL::Surface->new_from( $old_surface, ... );
112 <h3 id="Construtor_Parameters">Construtor Parameters</h3>
113 <div id="Construtor_Parameters_CONTENT">
116 <h4 id="flags">flags</h4>
117 <div id="flags_CONTENT">
118 <p>Available flags for new() are exported by SDL::Video</p>
120 <dt>SDL_ASYNCBLIT</dt>
122 <p>Use asynchronous blit if possible</p>
124 <dt>SDL_SWSURFACE</dt>
126 <p>Stored in the system memory.</p>
128 <dt>SDL_HWSURFACE</dt>
130 <p>Stored in video memory</p>
137 <p>SDL::Surface width are defined at construction. Thus the following is read only. </p>
138 <pre> my $w = $surface->w;
145 <p>SDL::Surface height are defined at construction. Thus the following is read only. </p>
146 <pre> my $h = $surface->h;
151 <h2 id="format">format</h2>
152 <div id="format_CONTENT">
153 <p>The format of the pixels stored in the surface. See <a href="SDL-PixelFormat.html">SDL::PixelFormat</a></p>
154 <pre> my $format = $surface->format;
159 <h2 id="pitch">pitch</h2>
160 <div id="pitch_CONTENT">
161 <pre> my $pitch = $surface->pitch;
164 <p>SDL::Surface's scanline length in bytes</p>
167 <h2 id="clip_rect">clip_rect</h2>
168 <div id="clip_rect_CONTENT">
169 <p>To get the surface's clip_rect we the following</p>
170 <pre> my $clip_rect = SDL::Rect->new(0,0,0,0);
171 SDL::Video::get_clip_rect($surface, $clip_rect);
174 <p>To set the surface's clip_rect use the following</p>
175 <pre> my $clip_rect = SDL::Rect->new(2,23,23,542);
176 SDL::Video::set_clip_rect($surface, $clip_rect);
181 <h1 id="Direct_Write_to_Surface_Pixel">Direct Write to Surface Pixel</h1><p><a href="#TOP" class="toplink">Top</a></p>
182 <div id="Direct_Write_to_Surface_Pixel_CONTEN">
183 <p>Disclaimer: This can be very slow, it is suitable for creating surfaces one time and not for animations</p>
186 <h2 id="get_pixels">get_pixels</h2>
187 <div id="get_pixels_CONTENT">
188 <pre> $surface->get_pixels( $offset )
191 <p>Returns the current integer value at (surface->pixels)[offset] </p>
194 <h2 id="set_pixels">set_pixels</h2>
195 <div id="set_pixels_CONTENT">
196 <pre> $surface->set_pixels( $offset, $value );
199 <p>Sets the current integer to $value at (surface->pixels)[offset]</p>
202 <h3 id="Usage">Usage</h3>
203 <div id="Usage_CONTENT">
206 my($x, $y, $color) = @_;
207 my $lineoffset = $y * ($screen->pitch / $depth_in_bytes);
208 $screen->set_pixels( $lineoffset+ $x, $color);
212 <p>Note: $depth_in_bytes for 32 is 4, 16 is 2, 8 is 1;</p>
213 <p>See also examples/sols/ch02.pl</p>
216 <h2 id="get_pixels_ptr">get_pixels_ptr</h2>
217 <div id="get_pixels_ptr_CONTENT">
218 <pre> $surface->get_pixels_ptr();
221 <p>Returns the C ptr to this surfaces's pixels</p>
231 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
232 <div id="SEE_ALSO_CONTENT">
233 <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>