NAME
SDL::Surface - Graphic surface structure.
CATEGORY
Core, Video, Structure
SYNOPSIS
The main surface (display) is provided by SDL::Video::set_video_mode. use SDL; #provides flags & constants use SDL::Video; #provides access to set_video_mode use SDL::Surface; #provides access to SDL_Surface struct internals
SDL::init(SDL_INIT_VIDEO);
my $display = SDL::Video::set_video_mode();
All surfaces constructed from now on are attached to the $display. There are two constructors available to do this.
my $surface = SDL::Surface->new ( ... );
my $surface2 = SDL::Surface->new_from ( surface, ... );
DESCRIPTION
An SDL_Surface
defines a surfaceangular area of pixels.
METHODS
new ( flags, width, height, depth, Rmask, Gmask, Bmask, Amask )
The constructor creates a new surface with the specified parameter values.
my $surface = SDL::Surface->new( ... );
new_from ( surface, width, height, depth, Rmask, Gmask, Bmask, Amask )
The constructor creates a new surface with the specified parameter values.
my $surface = SDL::Surface->new_from( $old_surface, ... );
Construtor Parameters
flags
- SDL_ANYFORMAT
-
Allow any pixel-format *
- SDL_ASYNCBLIT
-
Use asynchronous blit if possible
- SDL_DOUBLEBUF
-
Double buffered *
- SDL_HWACCEL
-
Use hardware acceleration blit
- SDL_HWPALETTE
-
Have an exclusive palette
- SDL_HWSURFACE
-
Stored in video memory
- SDL_FULLSCREEN
-
Full screen surface *
- SDL_OPENGL
-
Have an OpenGL context *
- SDL_OPENGLBLIT
-
Support OpenGL blitting *. NOTE: This option is kept for compatibility only, and is not recommended for new code.
- SDL_RESIZABLE
-
Resizable surface *
- SDL_RLEACCEL
-
Accelerated colorkey blitting with RLE
- SDL_SRCALPHA
-
Use alpha blending blit
- SDL_SRCCOLORKEY
-
Use colorkey blitting
- SDL_SWSURFACE
-
Stored in the system memory. SDL_SWSURFACE is not actually a flag (it is defined as 0). A lack of SDL_HWSURFACE implies SDL_SWSURFACE
- SDL_PREALLOC
-
Use preallocated memory
w
SDL::Surface width are defined at construction. Thus the following is read only.
my $w = $surface->w;
h
SDL::Surface height are defined at construction. Thus the following is read only.
my $h = $surface->h;
format
The format of the pixels stored in the surface. See SDL::PixelFormat
my $format = $surface->format;
pitch
my $pitch = $surface->pitch;
SDL::Surface's scanline length in bytes
clip_rect
To get the surface's clip_rect we the following
my $clip_rect = SDL::Rect->new(0,0,0,0);
SDL::Video::get_clip_rect($surface, $clip_rect);
To set the surface's clip_rect use the following
my $clip_rect = SDL::Rect->new(2,23,23,542);
SDL::Video::set_clip_rect($surface, $clip_rect);
Direct Write to Surface Pixel
Disclaimer: This can be very slow, it is suitable for creating surfaces one time and not for animations
get_pixels
$surface->get_pixels( $offset )
Returns the current integer value at (surface->pixels)[offset]
set_pixels
$surface->set_pixels( $offset, $value );
Sets the current integer to $value at (surface->pixels)[offset]
Usage
sub putpixel
{
my($x, $y, $color) = @_;
my $lineoffset = $y * ($screen->pitch / $depth_in_bytes);
$screen->set_pixels( $lineoffset+ $x, $color);
}
Note: $depth_in_bytes for 32 is 4, 16 is 2, 8 is 1;
See also examples/sols/ch02.pl
get_pixels_ptr
$surface->get_pixels_ptr();
Returns the C ptr to this surfaces's pixels