test/testsprite.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1516 4d241ea8a1cd
child 1666 6e7ec5cb83c3
     1.1 --- a/test/testsprite.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/test/testsprite.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -22,302 +22,306 @@
     1.4  Uint16 sprite_w, sprite_h;
     1.5  
     1.6  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.7 -static void quit(int rc)
     1.8 +static void
     1.9 +quit (int rc)
    1.10  {
    1.11 -	SDL_Quit();
    1.12 -	exit(rc);
    1.13 +    SDL_Quit ();
    1.14 +    exit (rc);
    1.15  }
    1.16  
    1.17 -int LoadSprite(char *file)
    1.18 +int
    1.19 +LoadSprite (char *file)
    1.20  {
    1.21 -	SDL_Surface *temp;
    1.22 +    SDL_Surface *temp;
    1.23  
    1.24 -	/* Load the sprite image */
    1.25 -	sprite = SDL_LoadBMP(file);
    1.26 -	if ( sprite == NULL ) {
    1.27 -		fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
    1.28 -		return(-1);
    1.29 -	}
    1.30 +    /* Load the sprite image */
    1.31 +    sprite = SDL_LoadBMP (file);
    1.32 +    if (sprite == NULL) {
    1.33 +        fprintf (stderr, "Couldn't load %s: %s", file, SDL_GetError ());
    1.34 +        return (-1);
    1.35 +    }
    1.36  
    1.37 -	/* Set transparent pixel as the pixel at (0,0) */
    1.38 -	if ( sprite->format->palette ) {
    1.39 -		SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL),
    1.40 -						*(Uint8 *)sprite->pixels);
    1.41 -	}
    1.42 +    /* Set transparent pixel as the pixel at (0,0) */
    1.43 +    if (sprite->format->palette) {
    1.44 +        SDL_SetColorKey (sprite, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
    1.45 +                         *(Uint8 *) sprite->pixels);
    1.46 +    }
    1.47  
    1.48 -	/* Convert sprite to video format */
    1.49 -	temp = SDL_DisplayFormat(sprite);
    1.50 -	SDL_FreeSurface(sprite);
    1.51 -	if ( temp == NULL ) {
    1.52 -		fprintf(stderr, "Couldn't convert background: %s\n",
    1.53 -							SDL_GetError());
    1.54 -		return(-1);
    1.55 -	}
    1.56 -	sprite = temp;
    1.57 +    /* Convert sprite to video format */
    1.58 +    temp = SDL_DisplayFormat (sprite);
    1.59 +    SDL_FreeSurface (sprite);
    1.60 +    if (temp == NULL) {
    1.61 +        fprintf (stderr, "Couldn't convert background: %s\n",
    1.62 +                 SDL_GetError ());
    1.63 +        return (-1);
    1.64 +    }
    1.65 +    sprite = temp;
    1.66  
    1.67 -	/* We're ready to roll. :) */
    1.68 -	return(0);
    1.69 +    /* We're ready to roll. :) */
    1.70 +    return (0);
    1.71  }
    1.72  
    1.73 -void MoveSprites(SDL_Surface *screen, Uint32 background)
    1.74 +void
    1.75 +MoveSprites (SDL_Surface * screen, Uint32 background)
    1.76  {
    1.77 -	int i, nupdates;
    1.78 -	SDL_Rect area, *position, *velocity;
    1.79 +    int i, nupdates;
    1.80 +    SDL_Rect area, *position, *velocity;
    1.81  
    1.82 -	nupdates = 0;
    1.83 -	/* Erase all the sprites if necessary */
    1.84 -	if ( sprites_visible ) {
    1.85 -		SDL_FillRect(screen, NULL, background);
    1.86 -	}
    1.87 +    nupdates = 0;
    1.88 +    /* Erase all the sprites if necessary */
    1.89 +    if (sprites_visible) {
    1.90 +        SDL_FillRect (screen, NULL, background);
    1.91 +    }
    1.92  
    1.93 -	/* Move the sprite, bounce at the wall, and draw */
    1.94 -	for ( i=0; i<numsprites; ++i ) {
    1.95 -		position = &positions[i];
    1.96 -		velocity = &velocities[i];
    1.97 -		position->x += velocity->x;
    1.98 -		if ( (position->x < 0) || (position->x >= (screen->w - sprite_w)) ) {
    1.99 -			velocity->x = -velocity->x;
   1.100 -			position->x += velocity->x;
   1.101 -		}
   1.102 -		position->y += velocity->y;
   1.103 -		if ( (position->y < 0) || (position->y >= (screen->h - sprite_w)) ) {
   1.104 -			velocity->y = -velocity->y;
   1.105 -			position->y += velocity->y;
   1.106 -		}
   1.107 +    /* Move the sprite, bounce at the wall, and draw */
   1.108 +    for (i = 0; i < numsprites; ++i) {
   1.109 +        position = &positions[i];
   1.110 +        velocity = &velocities[i];
   1.111 +        position->x += velocity->x;
   1.112 +        if ((position->x < 0) || (position->x >= (screen->w - sprite_w))) {
   1.113 +            velocity->x = -velocity->x;
   1.114 +            position->x += velocity->x;
   1.115 +        }
   1.116 +        position->y += velocity->y;
   1.117 +        if ((position->y < 0) || (position->y >= (screen->h - sprite_w))) {
   1.118 +            velocity->y = -velocity->y;
   1.119 +            position->y += velocity->y;
   1.120 +        }
   1.121  
   1.122 -		/* Blit the sprite onto the screen */
   1.123 -		area = *position;
   1.124 -		SDL_BlitSurface(sprite, NULL, screen, &area);
   1.125 -		sprite_rects[nupdates++] = area;
   1.126 -	}
   1.127 +        /* Blit the sprite onto the screen */
   1.128 +        area = *position;
   1.129 +        SDL_BlitSurface (sprite, NULL, screen, &area);
   1.130 +        sprite_rects[nupdates++] = area;
   1.131 +    }
   1.132  
   1.133 -	if (debug_flip) {
   1.134 -		if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
   1.135 -			static int t = 0;
   1.136 +    if (debug_flip) {
   1.137 +        if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
   1.138 +            static int t = 0;
   1.139  
   1.140 -			Uint32 color = SDL_MapRGB (screen->format, 255, 0, 0);
   1.141 -			SDL_Rect r;
   1.142 -			r.x = (sin((float)t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w-20);
   1.143 -			r.y = 0;
   1.144 -			r.w = 20;
   1.145 -			r.h = screen->h;
   1.146 +            Uint32 color = SDL_MapRGB (screen->format, 255, 0, 0);
   1.147 +            SDL_Rect r;
   1.148 +            r.x =
   1.149 +                (sin ((float) t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w - 20);
   1.150 +            r.y = 0;
   1.151 +            r.w = 20;
   1.152 +            r.h = screen->h;
   1.153  
   1.154 -			SDL_FillRect (screen, &r, color);
   1.155 -			t+=2;
   1.156 -		}
   1.157 -	}
   1.158 +            SDL_FillRect (screen, &r, color);
   1.159 +            t += 2;
   1.160 +        }
   1.161 +    }
   1.162  
   1.163 -	/* Update the screen! */
   1.164 -	if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
   1.165 -		SDL_Flip(screen);
   1.166 -	} else {
   1.167 -		SDL_UpdateRects(screen, nupdates, sprite_rects);
   1.168 -	}
   1.169 -	sprites_visible = 1;
   1.170 +    /* Update the screen! */
   1.171 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
   1.172 +        SDL_Flip (screen);
   1.173 +    } else {
   1.174 +        SDL_UpdateRects (screen, nupdates, sprite_rects);
   1.175 +    }
   1.176 +    sprites_visible = 1;
   1.177  }
   1.178  
   1.179  /* This is a way of telling whether or not to use hardware surfaces */
   1.180 -Uint32 FastestFlags(Uint32 flags, int width, int height, int bpp)
   1.181 +Uint32
   1.182 +FastestFlags (Uint32 flags, int width, int height, int bpp)
   1.183  {
   1.184 -	const SDL_VideoInfo *info;
   1.185 +    const SDL_VideoInfo *info;
   1.186  
   1.187 -	/* Hardware acceleration is only used in fullscreen mode */
   1.188 -	flags |= SDL_FULLSCREEN;
   1.189 +    /* Hardware acceleration is only used in fullscreen mode */
   1.190 +    flags |= SDL_FULLSCREEN;
   1.191  
   1.192 -	/* Check for various video capabilities */
   1.193 -	info = SDL_GetVideoInfo();
   1.194 -	if ( info->blit_hw_CC && info->blit_fill ) {
   1.195 -		/* We use accelerated colorkeying and color filling */
   1.196 -		flags |= SDL_HWSURFACE;
   1.197 -	}
   1.198 -	/* If we have enough video memory, and will use accelerated
   1.199 -	   blits directly to it, then use page flipping.
   1.200 -	 */
   1.201 -	if ( (flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
   1.202 -		/* Direct hardware blitting without double-buffering
   1.203 -		   causes really bad flickering.
   1.204 -		 */
   1.205 -		if ( info->video_mem*1024 > (height*width*bpp/8) ) {
   1.206 -			flags |= SDL_DOUBLEBUF;
   1.207 -		} else {
   1.208 -			flags &= ~SDL_HWSURFACE;
   1.209 -		}
   1.210 -	}
   1.211 +    /* Check for various video capabilities */
   1.212 +    info = SDL_GetVideoInfo ();
   1.213 +    if (info->blit_hw_CC && info->blit_fill) {
   1.214 +        /* We use accelerated colorkeying and color filling */
   1.215 +        flags |= SDL_HWSURFACE;
   1.216 +    }
   1.217 +    /* If we have enough video memory, and will use accelerated
   1.218 +       blits directly to it, then use page flipping.
   1.219 +     */
   1.220 +    if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   1.221 +        /* Direct hardware blitting without double-buffering
   1.222 +           causes really bad flickering.
   1.223 +         */
   1.224 +        if (info->video_mem * 1024 > (height * width * bpp / 8)) {
   1.225 +            flags |= SDL_DOUBLEBUF;
   1.226 +        } else {
   1.227 +            flags &= ~SDL_HWSURFACE;
   1.228 +        }
   1.229 +    }
   1.230  
   1.231 -	/* Return the flags */
   1.232 -	return(flags);
   1.233 +    /* Return the flags */
   1.234 +    return (flags);
   1.235  }
   1.236  
   1.237 -int main(int argc, char *argv[])
   1.238 +int
   1.239 +main (int argc, char *argv[])
   1.240  {
   1.241 -	SDL_Surface *screen;
   1.242 -	Uint8 *mem;
   1.243 -	int width, height;
   1.244 -	Uint8  video_bpp;
   1.245 -	Uint32 videoflags;
   1.246 -	Uint32 background;
   1.247 -	int    i, done;
   1.248 -	SDL_Event event;
   1.249 -	Uint32 then, now, frames;
   1.250 +    SDL_DisplayMode mode;
   1.251 +    SDL_Surface *screen;
   1.252 +    Uint8 *mem;
   1.253 +    int width, height;
   1.254 +    Uint8 video_bpp;
   1.255 +    Uint32 videoflags;
   1.256 +    Uint32 background;
   1.257 +    int i, done;
   1.258 +    SDL_Event event;
   1.259 +    Uint32 then, now, frames;
   1.260  
   1.261 -	/* Initialize SDL */
   1.262 -	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   1.263 -		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
   1.264 -		return(1);
   1.265 -	}
   1.266 +    /* Initialize SDL */
   1.267 +    if (SDL_Init (SDL_INIT_VIDEO) < 0) {
   1.268 +        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.269 +        return (1);
   1.270 +    }
   1.271  
   1.272 -	numsprites = NUM_SPRITES;
   1.273 -	videoflags = SDL_SWSURFACE|SDL_ANYFORMAT;
   1.274 -	width = 640;
   1.275 -	height = 480;
   1.276 -	video_bpp = 8;
   1.277 -	debug_flip = 0;
   1.278 -	while ( argc > 1 ) {
   1.279 -		--argc;
   1.280 -		if ( strcmp(argv[argc-1], "-width") == 0 ) {
   1.281 -			width = atoi(argv[argc]);
   1.282 -			--argc;
   1.283 -		} else
   1.284 -		if ( strcmp(argv[argc-1], "-height") == 0 ) {
   1.285 -			height = atoi(argv[argc]);
   1.286 -			--argc;
   1.287 -		} else
   1.288 -		if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
   1.289 -			video_bpp = atoi(argv[argc]);
   1.290 -			videoflags &= ~SDL_ANYFORMAT;
   1.291 -			--argc;
   1.292 -		} else
   1.293 -		if ( strcmp(argv[argc], "-fast") == 0 ) {
   1.294 -			videoflags = FastestFlags(videoflags, width, height, video_bpp);
   1.295 -		} else
   1.296 -		if ( strcmp(argv[argc], "-hw") == 0 ) {
   1.297 -			videoflags ^= SDL_HWSURFACE;
   1.298 -		} else
   1.299 -		if ( strcmp(argv[argc], "-flip") == 0 ) {
   1.300 -			videoflags ^= SDL_DOUBLEBUF;
   1.301 -		} else
   1.302 -		if ( strcmp(argv[argc], "-debugflip") == 0 ) {
   1.303 -			debug_flip ^= 1;
   1.304 -		} else
   1.305 -		if ( strcmp(argv[argc], "-fullscreen") == 0 ) {
   1.306 -			videoflags ^= SDL_FULLSCREEN;
   1.307 -		} else
   1.308 -		if ( isdigit(argv[argc][0]) ) {
   1.309 -			numsprites = atoi(argv[argc]);
   1.310 -		} else {
   1.311 -			fprintf(stderr, 
   1.312 -	"Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n",
   1.313 -								argv[0]);
   1.314 -			quit(1);
   1.315 -		}
   1.316 -	}
   1.317 +    numsprites = NUM_SPRITES;
   1.318 +    videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
   1.319 +    width = 640;
   1.320 +    height = 480;
   1.321 +    video_bpp = 8;
   1.322 +    debug_flip = 0;
   1.323 +    while (argc > 1) {
   1.324 +        --argc;
   1.325 +        if (strcmp (argv[argc - 1], "-width") == 0) {
   1.326 +            width = atoi (argv[argc]);
   1.327 +            --argc;
   1.328 +        } else if (strcmp (argv[argc - 1], "-height") == 0) {
   1.329 +            height = atoi (argv[argc]);
   1.330 +            --argc;
   1.331 +        } else if (strcmp (argv[argc - 1], "-bpp") == 0) {
   1.332 +            video_bpp = atoi (argv[argc]);
   1.333 +            videoflags &= ~SDL_ANYFORMAT;
   1.334 +            --argc;
   1.335 +        } else if (strcmp (argv[argc], "-fast") == 0) {
   1.336 +            videoflags = FastestFlags (videoflags, width, height, video_bpp);
   1.337 +        } else if (strcmp (argv[argc], "-hw") == 0) {
   1.338 +            videoflags ^= SDL_HWSURFACE;
   1.339 +        } else if (strcmp (argv[argc], "-flip") == 0) {
   1.340 +            videoflags ^= SDL_DOUBLEBUF;
   1.341 +        } else if (strcmp (argv[argc], "-debugflip") == 0) {
   1.342 +            debug_flip ^= 1;
   1.343 +        } else if (strcmp (argv[argc], "-fullscreen") == 0) {
   1.344 +            videoflags ^= SDL_FULLSCREEN;
   1.345 +        } else if (isdigit (argv[argc][0])) {
   1.346 +            numsprites = atoi (argv[argc]);
   1.347 +        } else {
   1.348 +            fprintf (stderr,
   1.349 +                     "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n",
   1.350 +                     argv[0]);
   1.351 +            quit (1);
   1.352 +        }
   1.353 +    }
   1.354  
   1.355 -	/* Set video mode */
   1.356 -	screen = SDL_SetVideoMode(width, height, video_bpp, videoflags);
   1.357 -	if ( ! screen ) {
   1.358 -		fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
   1.359 -					width, height, SDL_GetError());
   1.360 -		quit(2);
   1.361 -	}
   1.362 +    /* Set video mode */
   1.363 +    mode.format = 0;            /* FIXME */
   1.364 +    mode.w = width;
   1.365 +    mode.h = height;
   1.366 +    mode.refresh_rate = 0;
   1.367 +    screen = SDL_SetDisplayMode (&mode, videoflags);
   1.368 +    if (!screen) {
   1.369 +        fprintf (stderr, "Couldn't set %dx%d video mode: %s\n",
   1.370 +                 width, height, SDL_GetError ());
   1.371 +        quit (2);
   1.372 +    }
   1.373  
   1.374 -	/* Load the sprite */
   1.375 -	if ( LoadSprite("icon.bmp") < 0 ) {
   1.376 -		quit(1);
   1.377 -	}
   1.378 +    /* Load the sprite */
   1.379 +    if (LoadSprite ("icon.bmp") < 0) {
   1.380 +        quit (1);
   1.381 +    }
   1.382  
   1.383 -	/* Allocate memory for the sprite info */
   1.384 -	mem = (Uint8 *)malloc(4*sizeof(SDL_Rect)*numsprites);
   1.385 -	if ( mem == NULL ) {
   1.386 -		SDL_FreeSurface(sprite);
   1.387 -		fprintf(stderr, "Out of memory!\n");
   1.388 -		quit(2);
   1.389 -	}
   1.390 -	sprite_rects = (SDL_Rect *)mem;
   1.391 -	positions = sprite_rects;
   1.392 -	sprite_rects += numsprites;
   1.393 -	velocities = sprite_rects;
   1.394 -	sprite_rects += numsprites;
   1.395 -	sprite_w = sprite->w;
   1.396 -	sprite_h = sprite->h;
   1.397 -	srand(time(NULL));
   1.398 -	for ( i=0; i<numsprites; ++i ) {
   1.399 -		positions[i].x = rand()%(screen->w - sprite_w);
   1.400 -		positions[i].y = rand()%(screen->h - sprite_h);
   1.401 -		positions[i].w = sprite->w;
   1.402 -		positions[i].h = sprite->h;
   1.403 -		velocities[i].x = 0;
   1.404 -		velocities[i].y = 0;
   1.405 -		while ( ! velocities[i].x && ! velocities[i].y ) {
   1.406 -			velocities[i].x = (rand()%(MAX_SPEED*2+1))-MAX_SPEED;
   1.407 -			velocities[i].y = (rand()%(MAX_SPEED*2+1))-MAX_SPEED;
   1.408 -		}
   1.409 -	}
   1.410 -	background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
   1.411 +    /* Allocate memory for the sprite info */
   1.412 +    mem = (Uint8 *) malloc (4 * sizeof (SDL_Rect) * numsprites);
   1.413 +    if (mem == NULL) {
   1.414 +        SDL_FreeSurface (sprite);
   1.415 +        fprintf (stderr, "Out of memory!\n");
   1.416 +        quit (2);
   1.417 +    }
   1.418 +    sprite_rects = (SDL_Rect *) mem;
   1.419 +    positions = sprite_rects;
   1.420 +    sprite_rects += numsprites;
   1.421 +    velocities = sprite_rects;
   1.422 +    sprite_rects += numsprites;
   1.423 +    sprite_w = sprite->w;
   1.424 +    sprite_h = sprite->h;
   1.425 +    srand (time (NULL));
   1.426 +    for (i = 0; i < numsprites; ++i) {
   1.427 +        positions[i].x = rand () % (screen->w - sprite_w);
   1.428 +        positions[i].y = rand () % (screen->h - sprite_h);
   1.429 +        positions[i].w = sprite->w;
   1.430 +        positions[i].h = sprite->h;
   1.431 +        velocities[i].x = 0;
   1.432 +        velocities[i].y = 0;
   1.433 +        while (!velocities[i].x && !velocities[i].y) {
   1.434 +            velocities[i].x = (rand () % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
   1.435 +            velocities[i].y = (rand () % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
   1.436 +        }
   1.437 +    }
   1.438 +    background = SDL_MapRGB (screen->format, 0x00, 0x00, 0x00);
   1.439  
   1.440 -	/* Print out information about our surfaces */
   1.441 -	printf("Screen is at %d bits per pixel\n",screen->format->BitsPerPixel);
   1.442 -	if ( (screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
   1.443 -		printf("Screen is in video memory\n");
   1.444 -	} else {
   1.445 -		printf("Screen is in system memory\n");
   1.446 -	}
   1.447 -	if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
   1.448 -		printf("Screen has double-buffering enabled\n");
   1.449 -	}
   1.450 -	if ( (sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
   1.451 -		printf("Sprite is in video memory\n");
   1.452 -	} else {
   1.453 -		printf("Sprite is in system memory\n");
   1.454 -	}
   1.455 -	/* Run a sample blit to trigger blit acceleration */
   1.456 -	{ SDL_Rect dst;
   1.457 -		dst.x = 0;
   1.458 -		dst.y = 0;
   1.459 -		dst.w = sprite->w;
   1.460 -		dst.h = sprite->h;
   1.461 -		SDL_BlitSurface(sprite, NULL, screen, &dst);
   1.462 -		SDL_FillRect(screen, &dst, background);
   1.463 -	}
   1.464 -	if ( (sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
   1.465 -		printf("Sprite blit uses hardware acceleration\n");
   1.466 -	}
   1.467 -	if ( (sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
   1.468 -		printf("Sprite blit uses RLE acceleration\n");
   1.469 -	}
   1.470 +    /* Print out information about our surfaces */
   1.471 +    printf ("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel);
   1.472 +    if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   1.473 +        printf ("Screen is in video memory\n");
   1.474 +    } else {
   1.475 +        printf ("Screen is in system memory\n");
   1.476 +    }
   1.477 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
   1.478 +        printf ("Screen has double-buffering enabled\n");
   1.479 +    }
   1.480 +    if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   1.481 +        printf ("Sprite is in video memory\n");
   1.482 +    } else {
   1.483 +        printf ("Sprite is in system memory\n");
   1.484 +    }
   1.485 +    /* Run a sample blit to trigger blit acceleration */
   1.486 +    {
   1.487 +        SDL_Rect dst;
   1.488 +        dst.x = 0;
   1.489 +        dst.y = 0;
   1.490 +        dst.w = sprite->w;
   1.491 +        dst.h = sprite->h;
   1.492 +        SDL_BlitSurface (sprite, NULL, screen, &dst);
   1.493 +        SDL_FillRect (screen, &dst, background);
   1.494 +    }
   1.495 +    if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) {
   1.496 +        printf ("Sprite blit uses hardware acceleration\n");
   1.497 +    }
   1.498 +    if ((sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
   1.499 +        printf ("Sprite blit uses RLE acceleration\n");
   1.500 +    }
   1.501  
   1.502 -	/* Loop, blitting sprites and waiting for a keystroke */
   1.503 -	frames = 0;
   1.504 -	then = SDL_GetTicks();
   1.505 -	done = 0;
   1.506 -	sprites_visible = 0;
   1.507 -	while ( !done ) {
   1.508 -		/* Check for events */
   1.509 -		++frames;
   1.510 -		while ( SDL_PollEvent(&event) ) {
   1.511 -			switch (event.type) {
   1.512 -				case SDL_MOUSEBUTTONDOWN:
   1.513 -					SDL_WarpMouse(screen->w/2, screen->h/2);
   1.514 -					break;
   1.515 -				case SDL_KEYDOWN:
   1.516 -					/* Any keypress quits the app... */
   1.517 -				case SDL_QUIT:
   1.518 -					done = 1;
   1.519 -					break;
   1.520 -				default:
   1.521 -					break;
   1.522 -			}
   1.523 -		}
   1.524 -		MoveSprites(screen, background);
   1.525 -	}
   1.526 -	SDL_FreeSurface(sprite);
   1.527 -	free(mem);
   1.528 +    /* Loop, blitting sprites and waiting for a keystroke */
   1.529 +    frames = 0;
   1.530 +    then = SDL_GetTicks ();
   1.531 +    done = 0;
   1.532 +    sprites_visible = 0;
   1.533 +    while (!done) {
   1.534 +        /* Check for events */
   1.535 +        ++frames;
   1.536 +        while (SDL_PollEvent (&event)) {
   1.537 +            switch (event.type) {
   1.538 +            case SDL_MOUSEBUTTONDOWN:
   1.539 +                SDL_WarpMouse (screen->w / 2, screen->h / 2);
   1.540 +                break;
   1.541 +            case SDL_KEYDOWN:
   1.542 +                /* Any keypress quits the app... */
   1.543 +            case SDL_QUIT:
   1.544 +                done = 1;
   1.545 +                break;
   1.546 +            default:
   1.547 +                break;
   1.548 +            }
   1.549 +        }
   1.550 +        MoveSprites (screen, background);
   1.551 +    }
   1.552 +    SDL_FreeSurface (sprite);
   1.553 +    free (mem);
   1.554  
   1.555 -	/* Print out some timing information */
   1.556 -	now = SDL_GetTicks();
   1.557 -	if ( now > then ) {
   1.558 -		printf("%2.2f frames per second\n",
   1.559 -					((double)frames*1000)/(now-then));
   1.560 -	}
   1.561 -	SDL_Quit();
   1.562 -	return(0);
   1.563 +    /* Print out some timing information */
   1.564 +    now = SDL_GetTicks ();
   1.565 +    if (now > then) {
   1.566 +        printf ("%2.2f frames per second\n",
   1.567 +                ((double) frames * 1000) / (now - then));
   1.568 +    }
   1.569 +    SDL_Quit ();
   1.570 +    return (0);
   1.571  }