Advertisement
thecplusplusguy

SDL render multiple rect

Mar 6th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. //http://www.youtube.com/user/thecplusplusguy
  2. //multiple rect
  3. #include <SDL/SDL.h>
  4.  
  5. int main()
  6. {
  7.     SDL_Init(SDL_INIT_EVERYTHING);
  8.     SDL_Surface* screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
  9.    
  10.     Uint32 start;
  11.     SDL_Event event;
  12.     bool running=true;
  13.     SDL_Rect rec1;
  14.     SDL_Rect rec2;
  15.     rec1.x=60;
  16.     rec1.y=90;
  17.     rec1.w=30;
  18.     rec1.h=30;
  19.    
  20.    
  21.     rec2.x=140;
  22.     rec2.y=120;
  23.     rec2.w=30;
  24.     rec2.h=30;
  25.     while(running)
  26.     {
  27.         start=SDL_GetTicks();
  28.         while(SDL_PollEvent(&event))
  29.         {
  30.             switch(event.type)
  31.             {
  32.                 case SDL_QUIT:
  33.                     running=false;
  34.                     break;
  35.                 case SDL_KEYDOWN:
  36.                     switch(event.key.keysym.sym)
  37.                     {
  38.                         case SDLK_ESCAPE:
  39.                             running=false;
  40.                             break;
  41.                     }
  42.             }
  43.         }
  44.  
  45.         SDL_FillRect(screen,&rec1,SDL_MapRGB(screen->format,255,0,0));
  46.         SDL_FillRect(screen,&rec2,SDL_MapRGB(screen->format,0,0,255));
  47.         SDL_Flip(screen);
  48.  
  49.    
  50.         if(1000.0/30>SDL_GetTicks()-start)
  51.             SDL_Delay(1000.0/30-(SDL_GetTicks()-start));
  52.     }
  53.  
  54.    
  55.     SDL_Quit();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement