X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcore_surface.t;h=9e715e9981a8656355ba10d9d27a6ec32f07df6d;hb=babb07ed9fd8bafa78e6e1b0e6b17ed69d60ea84;hp=958df3eefb764a654840c3e9c2fc0d1ab98178f5;hpb=5ae1d2eef5903cd44b5afce4359f5fa4c665c8cc;p=sdlgit%2FSDL_perl.git diff --git a/t/core_surface.t b/t/core_surface.t index 958df3e..9e715e9 100644 --- a/t/core_surface.t +++ b/t/core_surface.t @@ -5,8 +5,8 @@ # BEGIN { - unshift @INC, 'blib/lib','blib/arch'; - } + unshift @INC, 'blib/lib', 'blib/arch'; +} use strict; use SDL; @@ -15,28 +15,87 @@ use SDL::Surface; use SDL::App; use SDL::Rect; use SDL::Color; -use Test::More; +use SDL::PixelFormat; +use Test::More tests => 35; -plan (tests => 2 ); +my $surface + = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 ); +isa_ok( $surface, 'SDL::Surface' ); +is( $surface->w, 640, 'surface has width' ); +is( $surface->h, 320, 'surface has height' ); +is( $surface->pitch, 640, 'surface has pitch' ); +my $clip_rect = SDL::Rect->new( 0, 0, 0, 0 ); +SDL::GetClipRect( $surface, $clip_rect ); +isa_ok( $clip_rect, 'SDL::Rect' ); +is( $clip_rect->x, 0, 'clip_rect has x' ); +is( $clip_rect->y, 0, 'clip_rect has y' ); +is( $clip_rect->w, 640, 'clip_rect has width' ); +is( $clip_rect->h, 320, 'clip_rect has height' ); +my $image = SDL::IMG_Load('test/data/logo.png'); +is( $image->w, 608, 'image has width' ); +is( $image->h, 126, 'image has height' ); -my $app = SDL::App->new(-title => "Test", -width => 640, -height => 480, -init => SDL_INIT_VIDEO); +my $pixel_format = $image->format; +isa_ok( $pixel_format, 'SDL::PixelFormat' ); +is( $pixel_format->BitsPerPixel, 24, '24 BitsPerPixel' ); +is( $pixel_format->BytesPerPixel, 3, '3 BytesPerPixel' ); +is( $pixel_format->Rloss, 0, '0 Rloss' ); +is( $pixel_format->Gloss, 0, '0 Gloss' ); +is( $pixel_format->Bloss, 0, '0 Bloss' ); +is( $pixel_format->Aloss, 8, '8 Aloss' ); +is( $pixel_format->Rshift, 0, '0 Rshift' ); +is( $pixel_format->Gshift, 8, '8 Gshift' ); +is( $pixel_format->Bshift, 16, '16 Bshift' ); +is( $pixel_format->Ashift, 0, '0 Ashift' ); +is( $pixel_format->Rmask, 255, '255 Rmask' ); +is( $pixel_format->Gmask, 65280, '65280 Gmask' ); +is( $pixel_format->Bmask, 16711680, '16711680 Bmask' ); +is( $pixel_format->Amask, 0, '0 Amask' ); +is( $pixel_format->colorkey, 0, '0 colorkey' ); +is( $pixel_format->alpha, 255, '255 alpha' ); + +my $pixel = SDL::MapRGB( $pixel_format, 255, 127, 0 ); +is( $pixel, 32767, '32767 pixel' ); +SDL::FillRect( $surface, SDL::Rect->new( 0, 0, 32, 32 ), $pixel ); +ok( 1, 'Managed to fill_rect' ); + +my $small_rect = SDL::Rect->new( 0, 0, 64, 64 ); +SDL::BlitSurface( $image, $small_rect, $surface, $small_rect ); +ok( 1, 'Managed to blit' ); + +#my $image_format = $surface->display; +#$surface->update_rect( 0, 0, 32, 32 ); +#ok( 1, 'Managed to update_rect' ); +#$surface->update_rects( SDL::Rect->new( 0, 0, 32, 32 ) ); +#ok( 1, 'Managed to update_rects' ); + +my $app = SDL::App->new( + -title => "Test", + -width => 640, + -height => 480, + -init => SDL_INIT_VIDEO +); pass 'did this pass'; -my $rect = SDL::Rect->new(0,0, $app->w, $app->h); +my $image_format = SDL::DisplayFormat($image); +isa_ok( $image_format, 'SDL::Surface' ); +my $image_format_alpha = SDL::DisplayFormatAlpha($image); +isa_ok( $image_format_alpha, 'SDL::Surface' ); - my $blue = SDL::Color->new( - 0x00, - 0x00, - 0xff, - ); +my $app_pixel_format = $app->format; -$app->fill_rect($rect,$blue); +my $rect = SDL::Rect->new( 0, 0, $app->w, $app->h ); +my $blue_pixel = SDL::MapRGB( $app_pixel_format, 0x00, 0x00, 0xff ); +SDL::FillRect( $app, $rect, $blue_pixel ); +SDL::UpdateRect( $app, 0, 0, 0, 0 ); +SDL::UpdateRects( $app, $small_rect ); -diag('This is in surface : '.SDL::Surface::get_pixels($app)); +diag( 'This is in surface : ' . SDL::Surface::get_pixels($app) ); pass 'did this pass'; +SDL::Delay(100);