pods::...urface(3pm)
πΈ NAME πΈ
okay bestie, welcome to the pods::...urface(3pm) page from User Contributed Perl Documentation π. This one is all about SDL::Surface β the Graphic surface structure. Yep, that's the name, that's the vibe, slay. β¨
π CATEGORY π
It's giving Core, Video, Structure β all three, no cap. π
β¨ SYNOPSIS β¨
use SDL;
use SDL::Video;
use SDL::Surface;
# Create the main surface (display)
SDL::init(SDL_INIT_VIDEO);
my $display = SDL::Video::set_video_mode(640, 480, 16, SDL_SWSURFACE);
# Create other surfaces attached to the $display.
my $surface = SDL::Surface->new(SDL_ASYNCBLIT | SDL_HWSURFACE, 640, 480, 16, 0, 0, 0, 0);
my $surface2 = SDL::Surface->new_from($surface, 100, 100, 8, 0, 0, 0, 0);
π¦ DESCRIPTION π¦
An SDL_Surface defines a surfaceangular area of pixels. That's the whole mood. π«
π CONSTANTS π
The constants for SDL::Surface belong to SDL::Video, under the export tag of ':surface'. Iconic. π
SDL_ASYNCBLITβ Use asynchronous blit if possibleSDL_SWSURFACEβ Store in system memorySDL_HWSURFACEβ Store in video memory
π METHODS π
new
my $surface = SDL::Surface->new(
$flags, $width, $height, $depth, $Rmask, $Gmask, $Bmask, $Amask
);
The constructor creates a new surface with the specified parameter values. Very main character energy. π«Ά
The four mask values are the bits that the channel will ignore. For example, an Rmask of 0xFF will ignore that channel completely, making everything on the surface more green/blue. π
new_from
my $surface = SDL::Surface->new_from(
$surface, $width, $height, $depth, $Rmask, $Gmask, $Bmask, $Amask
);
The constructor creates a new surface with the specified parameter values. The flags are taken from the specified $surface. Reuse era! π
w
my $w = $surface->w;
Returns the width of the surface. SDL::Surface width is defined at construction so this is read-only. No take-backs, bestie. π
h
my $h = $surface->h;
Returns the height of the surface. SDL::Surface height is defined at construction so this is read-only. Same locked-in vibe. π
format
my $format = $surface->format;
The format of the pixels stored in the surface. See SDL::PixelFormat π
pitch
my $pitch = $surface->pitch;
The scanline length in bytes. Literally just that. π
βοΈ Direct Write to Surface Pixel βοΈ
Disclaimer: The following methods can be very slow, making them suitable for creating surfaces, but not for animations
Not me warning you bestie: slow and steady is cute for setup, not for animation. π’π
get_pixel
my $pixel = $surface->get_pixel( $offset )
Returns the numeric pixel value for the given $offset. The pixel value depends on current pixel format. π
Note: For surfaces with a palette (1 byte per pixel) the palette index is returned instead of color values.
set_pixels
$surface->set_pixels( $offset, $value );
Sets the pixel $value to the given $offset. The pixel value must fit the pixel format of the surface. π―
Note: For surfaces with a palette (1 byte per pixel) the palette index must be passed instead of color values.
Example:
sub putpixel {
my ($x, $y, $color) = @_;
$display->set_pixels( $x + $y * $display->w, $color);
}
See also examples/pixel_operations/sols/ch02.pl! π«Ά
get_pixels_ptr
my $ptr = $surface->get_pixels_ptr;
Returns a reference to the surface's pixels. Pointy and powerful. πͺ
π SEE ALSO π
Check out SDL, SDL::PixelFormat, SDL::Video, SDL::Rect β the whole friend group. π«
π AUTHORS π
See "AUTHORS" in SDL. π
okay bye bestie β this was pods::...urface(3pm), from perl v5.42.0, dated 2024-05-01 πβ¨ Go slay your surfaces! π
π¦ where this page comes from
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms