Commit | Line | Data |
b7ed9095 |
1 | #!perl -w |
2 | # Copyright (C) 2009 kthakore |
3 | # |
4 | # Spec tests for SDL::Surface |
5 | # |
6 | |
7 | BEGIN { |
9a70569a |
8 | unshift @INC, 'blib/lib', 'blib/arch'; |
9 | } |
b7ed9095 |
10 | |
11 | use strict; |
12 | use SDL; |
13 | use SDL::Config; |
14 | use SDL::Surface; |
15 | use SDL::App; |
16 | use SDL::Rect; |
17 | use SDL::Color; |
f7de3b23 |
18 | use SDL::Video; |
50d9130a |
19 | use SDL::PixelFormat; |
2e2fd270 |
20 | use Test::More tests => 35; |
9a70569a |
21 | |
22 | my $surface |
af85b4e9 |
23 | = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 ); |
871d7fa3 |
24 | #TODO: test SDL::Surface->new_from |
9a70569a |
25 | isa_ok( $surface, 'SDL::Surface' ); |
af85b4e9 |
26 | is( $surface->w, 640, 'surface has width' ); |
27 | is( $surface->h, 320, 'surface has height' ); |
28 | is( $surface->pitch, 640, 'surface has pitch' ); |
29 | my $clip_rect = SDL::Rect->new( 0, 0, 0, 0 ); |
30 | SDL::GetClipRect( $surface, $clip_rect ); |
31 | isa_ok( $clip_rect, 'SDL::Rect' ); |
32 | is( $clip_rect->x, 0, 'clip_rect has x' ); |
33 | is( $clip_rect->y, 0, 'clip_rect has y' ); |
34 | is( $clip_rect->w, 640, 'clip_rect has width' ); |
35 | is( $clip_rect->h, 320, 'clip_rect has height' ); |
9a70569a |
36 | |
a7fbee87 |
37 | my $image = SDL::IMG_Load('test/data/logo.png'); |
9a70569a |
38 | is( $image->w, 608, 'image has width' ); |
39 | is( $image->h, 126, 'image has height' ); |
40 | |
50d9130a |
41 | my $pixel_format = $image->format; |
2e2fd270 |
42 | isa_ok( $pixel_format, 'SDL::PixelFormat' ); |
43 | is( $pixel_format->BitsPerPixel, 24, '24 BitsPerPixel' ); |
44 | is( $pixel_format->BytesPerPixel, 3, '3 BytesPerPixel' ); |
45 | is( $pixel_format->Rloss, 0, '0 Rloss' ); |
46 | is( $pixel_format->Gloss, 0, '0 Gloss' ); |
47 | is( $pixel_format->Bloss, 0, '0 Bloss' ); |
48 | is( $pixel_format->Aloss, 8, '8 Aloss' ); |
49 | is( $pixel_format->Rshift, 0, '0 Rshift' ); |
50 | is( $pixel_format->Gshift, 8, '8 Gshift' ); |
51 | is( $pixel_format->Bshift, 16, '16 Bshift' ); |
52 | is( $pixel_format->Ashift, 0, '0 Ashift' ); |
53 | is( $pixel_format->Rmask, 255, '255 Rmask' ); |
54 | is( $pixel_format->Gmask, 65280, '65280 Gmask' ); |
55 | is( $pixel_format->Bmask, 16711680, '16711680 Bmask' ); |
56 | is( $pixel_format->Amask, 0, '0 Amask' ); |
57 | is( $pixel_format->colorkey, 0, '0 colorkey' ); |
58 | is( $pixel_format->alpha, 255, '255 alpha' ); |
59 | |
60 | my $pixel = SDL::MapRGB( $pixel_format, 255, 127, 0 ); |
61 | is( $pixel, 32767, '32767 pixel' ); |
34a219f7 |
62 | SDL::FillRect( $surface, SDL::Rect->new( 0, 0, 32, 32 ), $pixel ); |
9a70569a |
63 | ok( 1, 'Managed to fill_rect' ); |
64 | |
65 | my $small_rect = SDL::Rect->new( 0, 0, 64, 64 ); |
2e2fd270 |
66 | SDL::BlitSurface( $image, $small_rect, $surface, $small_rect ); |
9a70569a |
67 | ok( 1, 'Managed to blit' ); |
68 | |
69 | #my $image_format = $surface->display; |
70 | #$surface->update_rect( 0, 0, 32, 32 ); |
71 | #ok( 1, 'Managed to update_rect' ); |
72 | #$surface->update_rects( SDL::Rect->new( 0, 0, 32, 32 ) ); |
73 | #ok( 1, 'Managed to update_rects' ); |
74 | |
75 | my $app = SDL::App->new( |
76 | -title => "Test", |
77 | -width => 640, |
78 | -height => 480, |
79 | -init => SDL_INIT_VIDEO |
80 | ); |
b7ed9095 |
81 | |
82 | pass 'did this pass'; |
83 | |
f7ce55ec |
84 | my $image_format = SDL::DisplayFormat($image); |
41a5a9ee |
85 | isa_ok( $image_format, 'SDL::Surface' ); |
86 | |
f7ce55ec |
87 | my $image_format_alpha = SDL::DisplayFormatAlpha($image); |
41a5a9ee |
88 | isa_ok( $image_format_alpha, 'SDL::Surface' ); |
89 | |
34a219f7 |
90 | my $app_pixel_format = $app->format; |
b7ed9095 |
91 | |
34a219f7 |
92 | my $rect = SDL::Rect->new( 0, 0, $app->w, $app->h ); |
b7ed9095 |
93 | |
34a219f7 |
94 | my $blue_pixel = SDL::MapRGB( $app_pixel_format, 0x00, 0x00, 0xff ); |
95 | SDL::FillRect( $app, $rect, $blue_pixel ); |
f7de3b23 |
96 | SDL::Video::update_rect( $app, 0, 0, 0, 0 ); |
97 | SDL::Video::update_rects( $app, $small_rect ); |
b7ed9095 |
98 | |
9a70569a |
99 | diag( 'This is in surface : ' . SDL::Surface::get_pixels($app) ); |
b7ed9095 |
100 | |
101 | pass 'did this pass'; |
102 | |
d5a2f5ac |
103 | SDL::delay(100); |