Guest User

Untitled

a guest
Mar 17th, 2012
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <os.h>
  2. #include <SDL.h>
  3.  
  4. #define NUM_BLITS   1000
  5.  
  6. #define RAND_RANGE(min, max) ((random() % (max - min + 1)) + min)
  7.  
  8. unsigned int random(void) {
  9.     static unsigned int u = 1234, v = 1234;
  10.     v = (36969 * (v & 65535)) + (v >> 16);
  11.     u = (18000 * (u & 65535)) + (u >> 16);
  12.     return (v << 16) + u;
  13. }
  14.  
  15. int main(void) {
  16.     SDL_Surface *screen, *tmp, *image;
  17.     SDL_nFont *font_vga;
  18.     Uint32 start, end;
  19.     int i;
  20.     int rand_wmax, rand_hmax;
  21.     char buf[256];
  22.     SDL_Rect pos;
  23.  
  24.     if(SDL_Init(SDL_INIT_VIDEO) == -1) {
  25.         printf("SDL_Init error: %s\n", SDL_GetError());
  26.         return 1;
  27.     }
  28.     screen = SDL_SetVideoMode(320, 240, NSP_BPP, SDL_SWSURFACE);
  29.     if(screen == NULL) {
  30.         printf("SDL_SetVideoMode error: %s\n", SDL_GetError());
  31.         return 1;
  32.     }
  33.     font_vga = SDL_nLoadFont(NSP_FONT_VGA, SDL_MapRGB(screen->format, 255, 0, 255), NSP_FONT_OPAQUE);
  34.     tmp = SDL_LoadBMP("Examples/image.bmp.tns");
  35.     if(tmp == NULL) {
  36.         printf("SDL_LoadBMP error: %s\n", SDL_GetError());
  37.         return 1;
  38.     }
  39.     image = SDL_DisplayFormat(tmp);
  40.     SDL_FreeSurface(tmp);
  41.     rand_wmax = 320 - image->w;
  42.     rand_hmax = 240 - image->h;
  43.     SDL_FillRect(screen, NULL, 0);
  44.     start = SDL_GetTicks();
  45.     for(i = 0; i < NUM_BLITS; ++i) {
  46.         pos.x = RAND_RANGE(0, rand_wmax);
  47.         pos.y = RAND_RANGE(0, rand_hmax);
  48.         SDL_BlitSurface(image, NULL, screen, &pos);
  49.         SDL_UpdateRect(screen, pos.x, pos.y, image->w, image->h);
  50.     }
  51.     end = SDL_GetTicks();
  52.     sprintf(buf, "%d blits in %u ms", NUM_BLITS, (unsigned int)(end - start));
  53.     SDL_nDrawString(screen, buf, 10, 10, font_vga);
  54.     SDL_Flip(screen);
  55.     SDL_Delay(10000);
  56.     SDL_nFreeFont(font_vga);
  57.     SDL_FreeSurface(image);
  58.     SDL_Quit();
  59.  
  60.     return 0;
  61. }
RAW Paste Data