2 # Copyright (C) 2009 kthakore
4 # Spec tests for SDL::Surface
8 unshift @INC, 'blib/lib', 'blib/arch';
19 use Test::More tests => 34;
22 = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 );
23 isa_ok( $surface, 'SDL::Surface' );
24 is( $surface->w, 640, 'surface has width' );
25 is( $surface->h, 320, 'surface has height' );
26 is( $surface->pitch, 640, 'surface has pitch' );
27 my $clip_rect = SDL::Rect->new( 0, 0, 0, 0 );
28 SDL::GetClipRect( $surface, $clip_rect );
29 isa_ok( $clip_rect, 'SDL::Rect' );
30 is( $clip_rect->x, 0, 'clip_rect has x' );
31 is( $clip_rect->y, 0, 'clip_rect has y' );
32 is( $clip_rect->w, 640, 'clip_rect has width' );
33 is( $clip_rect->h, 320, 'clip_rect has height' );
35 my $image = SDL::IMG_Load('test/data/logo.png');
36 is( $image->w, 608, 'image has width' );
37 is( $image->h, 126, 'image has height' );
39 my $pixel_format = $image->format;
40 isa_ok($pixel_format, 'SDL::PixelFormat');
41 is($pixel_format->BitsPerPixel, 24, '24 BitsPerPixel');
42 is($pixel_format->BytesPerPixel, 3, '3 BytesPerPixel');
43 is($pixel_format->Rloss, 0, '0 Rloss');
44 is($pixel_format->Gloss, 0, '0 Gloss');
45 is($pixel_format->Bloss, 0, '0 Bloss');
46 is($pixel_format->Aloss, 8, '8 Aloss');
47 is($pixel_format->Rshift, 0, '0 Rshift');
48 is($pixel_format->Gshift, 8, '8 Gshift');
49 is($pixel_format->Bshift, 16, '16 Bshift');
50 is($pixel_format->Ashift, 0, '0 Ashift');
51 is($pixel_format->Rmask, 255, '255 Rmask');
52 is($pixel_format->Gmask, 65280, '65280 Gmask');
53 is($pixel_format->Bmask, 16711680, '16711680 Bmask');
54 is($pixel_format->Amask, 0, '0 Amask');
55 is($pixel_format->colorkey, 0, '0 colorkey');
56 is($pixel_format->alpha, 255, '255 alpha');
58 $surface->fill_rect( SDL::Rect->new( 0, 0, 32, 32 ),
59 SDL::Color->new( 200, 200, 200 ) );
60 ok( 1, 'Managed to fill_rect' );
62 my $small_rect = SDL::Rect->new( 0, 0, 64, 64 );
63 SDL::BlitSurface($image, $small_rect, $surface, $small_rect );
64 ok( 1, 'Managed to blit' );
66 #my $image_format = $surface->display;
67 #$surface->update_rect( 0, 0, 32, 32 );
68 #ok( 1, 'Managed to update_rect' );
69 #$surface->update_rects( SDL::Rect->new( 0, 0, 32, 32 ) );
70 #ok( 1, 'Managed to update_rects' );
72 my $app = SDL::App->new(
76 -init => SDL_INIT_VIDEO
81 my $image_format = $image->display;
82 isa_ok( $image_format, 'SDL::Surface' );
84 my $image_format_alpha = $image->display_alpha;
85 isa_ok( $image_format_alpha, 'SDL::Surface' );
87 my $rect = SDL::Rect->new( 0, 0, $app->w, $app->h );
89 my $blue = SDL::Color->new( 0x00, 0x00, 0xff, );
91 $app->fill_rect( $rect, $blue );
93 diag( 'This is in surface : ' . SDL::Surface::get_pixels($app) );