5 # adapted from SDL-1.2.x/test/testsprite.c
7 # Usage: testsprite.pl [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]
22 use vars qw/ $app $app_rect $background $event $sprite $sprite_rect $videoflags /;
24 ## User tweakable settings (via cmd-line)
27 'screen_width' => 640,
28 'screen_height' => 480,
37 ## Process commandline arguments
41 GetOptions("width:i" => \$settings{screen_width},
42 "height:i" => \$settings{screen_height},
43 "bpp:i" => \$settings{bpp},
44 "fast!" => \$settings{fast},
45 "hw!" => \$settings{hw},
46 "flip!" => \$settings{flip},
47 "fullscreen!" => \$settings{fullscreen},
48 "numsprites=i" => \$settings{numsprites},
52 ## Initialize application options
56 $settings{bpp} ||= 8; # default to 8 bits per pix
58 $videoflags |= SDL_HWACCEL if $settings{hw};
59 $videoflags |= SDL_DOUBLEBUF if $settings{flip};
60 $videoflags |= SDL_FULLSCREEN if $settings{fullscreen};
68 -width => $settings{screen_width},
69 -height=> $settings{screen_height},
70 -title => "testsprite",
71 -icon => "data/icon.bmp",
72 -flags => $videoflags,
75 $app_rect= SDL::Rect->new(0,0,
76 $settings{screen_height},
77 $settings{screen_width}
80 $background = $SDL::Color::black;
82 $sprite = new SDL::Surface(-name =>"data/icon.bmp");
84 # Set transparent pixel as the pixel at (0,0)
86 $sprite->display_format();
88 $sprite->set_color_key(SDL_SRCCOLORKEY,$sprite->pixel(0,0)); # sets the transparent color to that at (0,0)
91 $sprite_rect = SDL::Rect->new(0, 0, $sprite->width, $sprite->height);
93 $event = new SDL::Event();
100 if ( ($app->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
101 printf("Screen is in video memory\n");
103 printf("Screen is in system memory\n");
106 if ( ($app->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
107 printf("Screen has double-buffering enabled\n");
110 if ( ($sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
111 printf("Sprite is in video memory\n");
113 printf("Sprite is in system memory\n");
116 # Run a sample blit to trigger blit (if posssible)
117 # acceleration before the check just after
120 if ( ($sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
121 printf("Sprite blit uses hardware acceleration\n");
123 if ( ($sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
124 printf("Sprite blit uses RLE acceleration\n");
136 my $dest_rect = SDL::Rect->new($x, $y, $sprite->width, $sprite->height);
137 $sprite->blit($sprite_rect, $app, $dest_rect);
145 my $y=$settings{screen_height}>>1;
150 # process event queue
153 my $etype=$event->type;
156 last if ($etype eq SDL_QUIT );
157 last if (SDL::GetKeyState(SDLK_ESCAPE));
159 #$app->lock() if $app->lockp();
165 $app->fill($app_rect, $background);
167 foreach (1..$settings{numsprites})
169 put_sprite( $_*8, $y + (sin(($i+$_)*0.2)*($settings{screen_height}/3)));
175 $app->flip if $settings{flip};