5 # adapted from SDL-1.2.x/test/testsprite.c
7 # Usage: testsprite.pl [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]
20 use vars qw/ $app $app_rect $background $event $sprite $sprite_rect $videoflags /;
22 ## User tweakable settings (via cmd-line)
25 'screen_width' => 640,
26 'screen_height' => 480,
35 ## Process commandline arguments
39 GetOptions("width:i" => \$settings{screen_width},
40 "height:i" => \$settings{screen_height},
41 "bpp:i" => \$settings{bpp},
42 "fast!" => \$settings{fast},
43 "hw!" => \$settings{hw},
44 "flip!" => \$settings{flip},
45 "fullscreen!" => \$settings{fullscreen},
46 "numsprites=i" => \$settings{numsprites},
50 ## Initialize application options
54 $settings{bpp} ||= 8; # default to 8 bits per pix
56 $videoflags |= SDL_HWACCEL if $settings{hw};
57 $videoflags |= SDL_DOUBLEBUF if $settings{flip};
58 $videoflags |= SDL_FULLSCREEN if $settings{fullscreen};
66 -width => $settings{screen_width},
67 -height=> $settings{screen_height},
68 -title => "testsprite",
69 -icon => "data/icon.bmp",
70 -flags => $videoflags,
73 $app_rect= new SDL::Rect(
74 -height => $settings{screen_height},
75 -width => $settings{screen_width},
78 $background = $SDL::Color::black;
80 $sprite = new SDL::Surface(-name =>"data/icon.bmp");
82 # Set transparent pixel as the pixel at (0,0)
84 $sprite->display_format();
86 $sprite->set_color_key(SDL_SRCCOLORKEY,$sprite->pixel(0,0)); # sets the transparent color to that at (0,0)
89 $sprite_rect = new SDL::Rect(-x => 0,
91 -width => $sprite->width,
92 -height=> $sprite->height,
95 $event = new SDL::Event();
102 if ( ($app->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
103 printf("Screen is in video memory\n");
105 printf("Screen is in system memory\n");
108 if ( ($app->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
109 printf("Screen has double-buffering enabled\n");
112 if ( ($sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
113 printf("Sprite is in video memory\n");
115 printf("Sprite is in system memory\n");
118 # Run a sample blit to trigger blit (if posssible)
119 # acceleration before the check just after
122 if ( ($sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
123 printf("Sprite blit uses hardware acceleration\n");
125 if ( ($sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
126 printf("Sprite blit uses RLE acceleration\n");
138 my $dest_rect = new SDL::Rect(-x => $x,
140 -width => $sprite->width,
141 -height => $sprite->height,
143 $sprite->blit($sprite_rect, $app, $dest_rect);
151 my $y=$settings{screen_height}>>1;
156 # process event queue
159 my $etype=$event->type;
162 last if ($etype eq SDL_QUIT );
163 last if (SDL::GetKeyState(SDLK_ESCAPE));
165 #$app->lock() if $app->lockp();
171 $app->fill($app_rect, $background);
173 foreach (1..$settings{numsprites})
175 put_sprite( $_*8, $y + (sin(($i+$_)*0.2)*($settings{screen_height}/3)));
181 $app->flip if $settings{flip};