Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <SDL/SDL.h>
- #include <SDL/SDL_image.h>
- #include <SDL/SDL_gfxPrimitives.h>
- #include <inttypes.h>
- #include <time.h>
- const uint32_t screen_w=320;
- const uint32_t screen_h=240;
- bool dones=false;
- uint64_t millisec()
- {
- struct timespec t;
- clock_gettime(CLOCK_MONOTONIC, &t);
- return (uint64_t)t.tv_sec * 1000 + t.tv_nsec / 1000000;
- }
- int main ( int argc, char** argv )
- {
- // initialize SDL video
- if ( SDL_Init( SDL_INIT_VIDEO) < 0 )
- {
- printf( "Unable to init SDL: %s\n", SDL_GetError() );
- return 1;
- }
- SDL_EnableKeyRepeat(50,SDL_DEFAULT_REPEAT_INTERVAL);
- // make sure SDL cleans up before exit
- atexit(SDL_Quit);
- Sint16 vx[5] = {10,150,160,140,9};
- Sint16 vy[5] = {5,100,130,120,60};
- //SDL_Surface* screen = SDL_SetVideoMode(screen_w, screen_h, 32,SDL_HWSURFACE|SDL_DOUBLEBUF);
- #ifdef DINGOO
- SDL_ShowCursor(SDL_DISABLE);
- SDL_Surface* screen = SDL_SetVideoMode(screen_w, screen_h, 16,SDL_SWSURFACE);
- #else
- SDL_Surface* screen = SDL_SetVideoMode(screen_w, screen_h, 32,SDL_SWSURFACE);
- #endif
- if ( !screen )
- {
- printf("Unable to set 320x240 video: %s\n", SDL_GetError());
- return 1;
- }
- while (!dones)
- {
- SDL_Event event;
- while (SDL_PollEvent(&event))
- {
- // check for messages
- switch (event.type)
- {
- // exit if the window is closed
- case SDL_QUIT:
- dones = true;
- break;
- // check for keypresses
- case SDL_KEYDOWN:
- {
- dones=true;
- }
- // case SDL_KEYUP:
- // {
- // Kii=event.key.keysym.sym;
- // }
- } // end switch
- //
- } // end of message processing
- SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 135, 0, 135));
- uint32_t num=0;
- uint8_t *p;
- uint64_t mill=millisec();
- while (mill+1000>millisec())
- {
- num++;
- /*uint32_t bpp = screen->format->BytesPerPixel;
- p=(uint8_t*)screen->pixels+(rand()%240)* screen->pitch+(rand()%320)*bpp;
- switch (bpp) {
- case 1:
- *p = rand() & 0xFF;
- break;
- case 2:
- *(Uint16 *) p = rand() & 0xFFFF;
- break;
- case 3:
- *(Uint32 *) p = rand() & 0xFFFFFF;
- break;
- case 4:
- *(Uint32 *) p = rand();
- break;
- }
- */
- //aapolygonRGBA(screen,vx,vy,7,0,0,0,255);
- //filledPolygonRGBA(screen,vx,vy,7,0,0,0,255);
- filledTrigonRGBA(screen,vx[0],vy[0],vx[1],vy[1],vx[2],vy[2],rand()%256,rand()%256,rand()%256,255);
- for (int i=0;i<3;i++)
- {
- vx[0]=rand()%320;
- vy[0]=rand()%240;
- vx[1]=vx[0]+rand()%60-30;
- vy[1]=vy[0]+rand()%60-30;
- vx[2]=vx[0]+rand()%60-30;
- vy[2]=vy[0]+rand()%60-30;
- }
- }
- printf("%d\n",num);
- mill=millisec();
- SDL_Flip(screen);
- //SDL_Delay(1000/10);
- } // end main loop
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement