Wrap PixelFormat
[sdlgit/SDL_perl.git] / t / core_surface.t
CommitLineData
b7ed9095 1#!perl -w
2# Copyright (C) 2009 kthakore
3#
4# Spec tests for SDL::Surface
5#
6
7BEGIN {
9a70569a 8 unshift @INC, 'blib/lib', 'blib/arch';
9}
b7ed9095 10
11use strict;
12use SDL;
13use SDL::Config;
14use SDL::Surface;
15use SDL::App;
16use SDL::Rect;
17use SDL::Color;
50d9130a 18use SDL::PixelFormat;
19use Test::More tests => 34;
9a70569a 20
21my $surface
af85b4e9 22 = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 );
9a70569a 23isa_ok( $surface, 'SDL::Surface' );
af85b4e9 24is( $surface->w, 640, 'surface has width' );
25is( $surface->h, 320, 'surface has height' );
26is( $surface->pitch, 640, 'surface has pitch' );
27my $clip_rect = SDL::Rect->new( 0, 0, 0, 0 );
28SDL::GetClipRect( $surface, $clip_rect );
29isa_ok( $clip_rect, 'SDL::Rect' );
30is( $clip_rect->x, 0, 'clip_rect has x' );
31is( $clip_rect->y, 0, 'clip_rect has y' );
32is( $clip_rect->w, 640, 'clip_rect has width' );
33is( $clip_rect->h, 320, 'clip_rect has height' );
9a70569a 34
a7fbee87 35my $image = SDL::IMG_Load('test/data/logo.png');
9a70569a 36is( $image->w, 608, 'image has width' );
37is( $image->h, 126, 'image has height' );
38
50d9130a 39my $pixel_format = $image->format;
40isa_ok($pixel_format, 'SDL::PixelFormat');
41is($pixel_format->BitsPerPixel, 24, '24 BitsPerPixel');
42is($pixel_format->BytesPerPixel, 3, '3 BytesPerPixel');
43is($pixel_format->Rloss, 0, '0 Rloss');
44is($pixel_format->Gloss, 0, '0 Gloss');
45is($pixel_format->Bloss, 0, '0 Bloss');
46is($pixel_format->Aloss, 8, '8 Aloss');
47is($pixel_format->Rshift, 0, '0 Rshift');
48is($pixel_format->Gshift, 8, '8 Gshift');
49is($pixel_format->Bshift, 16, '16 Bshift');
50is($pixel_format->Ashift, 0, '0 Ashift');
51is($pixel_format->Rmask, 255, '255 Rmask');
52is($pixel_format->Gmask, 65280, '65280 Gmask');
53is($pixel_format->Bmask, 16711680, '16711680 Bmask');
54is($pixel_format->Amask, 0, '0 Amask');
55is($pixel_format->colorkey, 0, '0 colorkey');
56is($pixel_format->alpha, 255, '255 alpha');
57
9a70569a 58$surface->fill_rect( SDL::Rect->new( 0, 0, 32, 32 ),
59 SDL::Color->new( 200, 200, 200 ) );
60ok( 1, 'Managed to fill_rect' );
61
62my $small_rect = SDL::Rect->new( 0, 0, 64, 64 );
348b98f1 63SDL::BlitSurface($image, $small_rect, $surface, $small_rect );
9a70569a 64ok( 1, 'Managed to blit' );
65
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' );
71
72my $app = SDL::App->new(
73 -title => "Test",
74 -width => 640,
75 -height => 480,
76 -init => SDL_INIT_VIDEO
77);
b7ed9095 78
79pass 'did this pass';
80
41a5a9ee 81my $image_format = $image->display;
82isa_ok( $image_format, 'SDL::Surface' );
83
84my $image_format_alpha = $image->display_alpha;
85isa_ok( $image_format_alpha, 'SDL::Surface' );
86
9a70569a 87my $rect = SDL::Rect->new( 0, 0, $app->w, $app->h );
b7ed9095 88
9a70569a 89my $blue = SDL::Color->new( 0x00, 0x00, 0xff, );
b7ed9095 90
9a70569a 91$app->fill_rect( $rect, $blue );
b7ed9095 92
9a70569a 93diag( 'This is in surface : ' . SDL::Surface::get_pixels($app) );
b7ed9095 94
95pass 'did this pass';
96