5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
7 # ------------------------------------------------------------------------------
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 # ------------------------------------------------------------------------------
25 # Please feel free to send questions, suggestions or improvements to:
33 use MIME::Base64 qw(decode_base64);
42 use vars qw/ $app $app_rect $background $event $sprite $sprite_rect $videoflags /;
44 ## User tweakable settings (via cmd-line)
47 'screen_width' => 640,
48 'screen_height' => 480,
57 ## Initialize application options
61 $settings{bpp} ||= 8; # default to 8 bits per pix
62 $videoflags |= SDL_HWACCEL if $settings{hw};
63 $videoflags |= SDL_DOUBLEBUF if $settings{flip};
64 $videoflags |= SDL_FULLSCREEN if $settings{fullscreen};
75 -width => $settings{screen_width},
76 -height=> $settings{screen_height},
77 -title => "testsprite",
78 -icon => "/tmp/icon.bmp",
79 -flags => $videoflags,
82 $app_rect= new SDL::Rect(
83 -height => $settings{screen_height},
84 -width => $settings{screen_width},
87 $background = $SDL::Color::black;
89 $sprite = new SDL::Surface(-name => '/tmp/icon.bmp');
91 # Set transparent pixel as the pixel at (0,0)
93 $sprite->display_format();
95 $sprite->set_color_key(SDL_SRCCOLORKEY,$sprite->pixel(0,0)); # sets the transparent color to that at (0,0)
98 $sprite_rect = new SDL::Rect(-x => 0,
100 -width => $sprite->width,
101 -height=> $sprite->height,
104 $event = new SDL::Event();
107 ## Prints diagnostics
111 if ( ($app->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
112 printf("Screen is in video memory\n");
114 printf("Screen is in system memory\n");
117 if ( ($app->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
118 printf("Screen has double-buffering enabled\n");
121 if ( ($sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
122 printf("Sprite is in video memory\n");
124 printf("Sprite is in system memory\n");
127 # Run a sample blit to trigger blit (if posssible)
128 # acceleration before the check just after
131 if ( ($sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
132 printf("Sprite blit uses hardware acceleration\n");
134 if ( ($sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
135 printf("Sprite blit uses RLE acceleration\n");
147 my $dest_rect = new SDL::Rect(-x => $x,
149 -width => $sprite->width,
150 -height => $sprite->height,
152 $sprite->blit($sprite_rect, $app, $dest_rect);
160 my $y=$settings{screen_height}>>1;
165 # process event queue
168 my $etype=$event->type;
171 last if ($etype eq SDL_QUIT );
172 last if (SDL::GetKeyState(SDLK_ESCAPE));
174 #$app->lock() if $app->lockp();
180 $app->fill($app_rect, $background);
182 foreach (1..$settings{numsprites})
184 put_sprite( $_*8, $y + (sin(($i+$_)*0.2)*($settings{screen_height}/3)));
190 $app->flip if $settings{flip};
200 system 'rm /tmp/icon.bmp';
205 $bmp = decode_base64 <<EOF;
206 Qk1CAgAAAAAAAEIAAAAoAAAAIAAAACAAAAABAAQAAAAAAAACAABtCwAAbQsAAAMAAAADAAAA////
207 AAAAAAAA//8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
208 AAAAAAAAAAAAAAAAAAAAAAAAAAAAABEREREAAAAAAAAAAAAAABEiIiIiEQAAAAAAAAAAAAEiIRER
209 EiIQAAAAAAAAAAASIRERERESIQAAAAAAAAABIhERERERESIQAAAAAAAAEiERIiIiIhESIQAAAAAA
210 ABIiIiIiIiIiIiEAAAAAAAEiIiIiIiIiIiIiEAAAAAABIiIiIiESIiIiIhAAAAAAASIiIiIhEiIi
211 IiIQAAAAAAEiIiIiIiIiIiIiEAAAAAABIiIiIiIiIiIiIhAAAAAAASIiEREiIhERIiIQAAAAAAEi
212 IhEBIiIRASIiEAAAAAAAEiIRESIiEREiIQAAAAAAABIiIiIiIiIiIiEAAAAAAAABIiIiIiIiIiIQ
213 AAAAAAAAABIiIiIiIiIhAAAAAAAAAAABIiIiIiIiEAAAAAAAAAAAABEiIiIiEQAAAAAAAAAAAAAA
214 EREREQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
215 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
218 open FP, "> /tmp/icon.bmp";