Advertisement
Guest User

Zidane

a guest
Jun 29th, 2010
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.29 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <SDL/SDL.h>
  3. #include <SDL/SDL_image.h>
  4. #include <SDL/SDL_gfxPrimitives.h>
  5. #include <inttypes.h>
  6. #include <time.h>
  7.  
  8. const uint32_t screen_w=320;
  9. const uint32_t screen_h=240;
  10.  
  11. bool dones=false;
  12.  
  13. uint64_t millisec()
  14. {
  15.     struct timespec t;
  16.     clock_gettime(CLOCK_MONOTONIC, &t);
  17.     return (uint64_t)t.tv_sec * 1000 + t.tv_nsec / 1000000;
  18. }
  19.  
  20.  
  21. int main ( int argc, char** argv )
  22. {
  23.  
  24.     // initialize SDL video
  25.     if ( SDL_Init( SDL_INIT_VIDEO) < 0 )
  26.     {
  27.         printf( "Unable to init SDL: %s\n", SDL_GetError() );
  28.         return 1;
  29.     }
  30.  
  31.     SDL_EnableKeyRepeat(50,SDL_DEFAULT_REPEAT_INTERVAL);
  32.  
  33.     // make sure SDL cleans up before exit
  34.     atexit(SDL_Quit);
  35.  
  36.     Sint16 vx[5] = {10,150,160,140,9};
  37.     Sint16 vy[5] = {5,100,130,120,60};
  38.  
  39.  
  40.  
  41.     //SDL_Surface* screen = SDL_SetVideoMode(screen_w, screen_h, 32,SDL_HWSURFACE|SDL_DOUBLEBUF);
  42. #ifdef DINGOO
  43.     SDL_ShowCursor(SDL_DISABLE);
  44.     SDL_Surface* screen = SDL_SetVideoMode(screen_w, screen_h, 16,SDL_SWSURFACE);
  45. #else
  46.     SDL_Surface* screen = SDL_SetVideoMode(screen_w, screen_h, 32,SDL_SWSURFACE);
  47. #endif
  48.  
  49.  
  50.  
  51.     if ( !screen )
  52.     {
  53.         printf("Unable to set 320x240 video: %s\n", SDL_GetError());
  54.         return 1;
  55.     }
  56.  
  57.  
  58.  
  59.  
  60.     while (!dones)
  61.     {
  62.  
  63.  
  64.         SDL_Event event;
  65.         while (SDL_PollEvent(&event))
  66.         {
  67.             // check for messages
  68.             switch (event.type)
  69.             {
  70.                 // exit if the window is closed
  71.             case SDL_QUIT:
  72.                 dones =  true;
  73.                 break;
  74.  
  75.                 // check for keypresses
  76.             case SDL_KEYDOWN:
  77.             {
  78.                 dones=true;
  79.             }
  80.             // case SDL_KEYUP:
  81.             // {
  82.             //     Kii=event.key.keysym.sym;
  83.             // }
  84.             } // end switch
  85.             //
  86.         } // end of message processing
  87.  
  88.  
  89.  
  90.         SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 135, 0, 135));
  91.  
  92.         uint32_t num=0;
  93.  
  94.         uint8_t *p;
  95.  
  96.         uint64_t mill=millisec();
  97.  
  98.         while (mill+1000>millisec())
  99.         {
  100.  
  101.         num++;
  102.         /*uint32_t bpp = screen->format->BytesPerPixel;
  103.         p=(uint8_t*)screen->pixels+(rand()%240)* screen->pitch+(rand()%320)*bpp;
  104.  
  105.         switch (bpp) {
  106.         case 1:
  107.             *p = rand() & 0xFF;
  108.             break;
  109.         case 2:
  110.             *(Uint16 *) p = rand() & 0xFFFF;
  111.             break;
  112.         case 3:
  113.             *(Uint32 *) p = rand() & 0xFFFFFF;
  114.             break;
  115.         case 4:
  116.             *(Uint32 *) p = rand();
  117.             break;
  118.         }
  119. */
  120.  
  121.  
  122.         //aapolygonRGBA(screen,vx,vy,7,0,0,0,255);
  123.         //filledPolygonRGBA(screen,vx,vy,7,0,0,0,255);
  124.         filledTrigonRGBA(screen,vx[0],vy[0],vx[1],vy[1],vx[2],vy[2],rand()%256,rand()%256,rand()%256,255);
  125.  
  126.         for (int i=0;i<3;i++)
  127.            {
  128.                 vx[0]=rand()%320;
  129.                 vy[0]=rand()%240;
  130.                 vx[1]=vx[0]+rand()%60-30;
  131.                 vy[1]=vy[0]+rand()%60-30;
  132.                 vx[2]=vx[0]+rand()%60-30;
  133.                 vy[2]=vy[0]+rand()%60-30;
  134.             }
  135.  
  136.         }
  137.  
  138.  
  139.  
  140.  
  141.         printf("%d\n",num);
  142.         mill=millisec();
  143.         SDL_Flip(screen);
  144.         //SDL_Delay(1000/10);
  145.  
  146.     } // end main loop
  147.  
  148.     return 0;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement