2 # Copyright (C) 2009 kthakore
4 # Spec tests for SDL::Surface
8 unshift @INC, 'blib/lib', 'blib/arch';
20 use Test::More tests => 35;
23 = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 );
24 isa_ok( $surface, 'SDL::Surface' );
25 is( $surface->w, 640, 'surface has width' );
26 is( $surface->h, 320, 'surface has height' );
27 is( $surface->pitch, 640, 'surface has pitch' );
28 my $clip_rect = SDL::Rect->new( 0, 0, 0, 0 );
29 SDL::GetClipRect( $surface, $clip_rect );
30 isa_ok( $clip_rect, 'SDL::Rect' );
31 is( $clip_rect->x, 0, 'clip_rect has x' );
32 is( $clip_rect->y, 0, 'clip_rect has y' );
33 is( $clip_rect->w, 640, 'clip_rect has width' );
34 is( $clip_rect->h, 320, 'clip_rect has height' );
36 my $image = SDL::IMG_Load('test/data/logo.png');
37 is( $image->w, 608, 'image has width' );
38 is( $image->h, 126, 'image has height' );
40 my $pixel_format = $image->format;
41 isa_ok( $pixel_format, 'SDL::PixelFormat' );
42 is( $pixel_format->BitsPerPixel, 24, '24 BitsPerPixel' );
43 is( $pixel_format->BytesPerPixel, 3, '3 BytesPerPixel' );
44 is( $pixel_format->Rloss, 0, '0 Rloss' );
45 is( $pixel_format->Gloss, 0, '0 Gloss' );
46 is( $pixel_format->Bloss, 0, '0 Bloss' );
47 is( $pixel_format->Aloss, 8, '8 Aloss' );
48 is( $pixel_format->Rshift, 0, '0 Rshift' );
49 is( $pixel_format->Gshift, 8, '8 Gshift' );
50 is( $pixel_format->Bshift, 16, '16 Bshift' );
51 is( $pixel_format->Ashift, 0, '0 Ashift' );
52 is( $pixel_format->Rmask, 255, '255 Rmask' );
53 is( $pixel_format->Gmask, 65280, '65280 Gmask' );
54 is( $pixel_format->Bmask, 16711680, '16711680 Bmask' );
55 is( $pixel_format->Amask, 0, '0 Amask' );
56 is( $pixel_format->colorkey, 0, '0 colorkey' );
57 is( $pixel_format->alpha, 255, '255 alpha' );
59 my $pixel = SDL::MapRGB( $pixel_format, 255, 127, 0 );
60 is( $pixel, 32767, '32767 pixel' );
61 SDL::FillRect( $surface, SDL::Rect->new( 0, 0, 32, 32 ), $pixel );
62 ok( 1, 'Managed to fill_rect' );
64 my $small_rect = SDL::Rect->new( 0, 0, 64, 64 );
65 SDL::BlitSurface( $image, $small_rect, $surface, $small_rect );
66 ok( 1, 'Managed to blit' );
68 #my $image_format = $surface->display;
69 #$surface->update_rect( 0, 0, 32, 32 );
70 #ok( 1, 'Managed to update_rect' );
71 #$surface->update_rects( SDL::Rect->new( 0, 0, 32, 32 ) );
72 #ok( 1, 'Managed to update_rects' );
74 my $app = SDL::App->new(
78 -init => SDL_INIT_VIDEO
83 my $image_format = SDL::DisplayFormat($image);
84 isa_ok( $image_format, 'SDL::Surface' );
86 my $image_format_alpha = SDL::DisplayFormatAlpha($image);
87 isa_ok( $image_format_alpha, 'SDL::Surface' );
89 my $app_pixel_format = $app->format;
91 my $rect = SDL::Rect->new( 0, 0, $app->w, $app->h );
93 my $blue_pixel = SDL::MapRGB( $app_pixel_format, 0x00, 0x00, 0xff );
94 SDL::FillRect( $app, $rect, $blue_pixel );
95 SDL::Video::update_rect( $app, 0, 0, 0, 0 );
96 SDL::Video::update_rects( $app, $small_rect );
98 diag( 'This is in surface : ' . SDL::Surface::get_pixels($app) );
100 pass 'did this pass';