Advertisement
thecplusplusguy

SDL tutorial 2

Jun 22nd, 2012
1,869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. //http://www.youtube.com/user/thecplusplusguy
  2. //Thanks for the typed in code to Tapit85
  3. #include <SDL/SDL.h>
  4.  
  5. int main(int argc, char** argv)
  6. {
  7.     SDL_Init(SDL_INIT_EVERYTHING);
  8.     SDL_Surface *screen;
  9.     screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
  10. //  screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE|SDL_FULLSCREEN);
  11.     bool running = true;
  12.     const int FPS = 30;
  13.     Uint32 start;
  14.     while(running) {
  15.         start = SDL_GetTicks();
  16.         SDL_Event event;
  17.         while(SDL_PollEvent(&event)) {
  18.             switch(event.type) {
  19.                 case SDL_QUIT:
  20.                     running = false;
  21.                     break;
  22.             }
  23.         }
  24.         //logic && render
  25.  
  26.  
  27.         SDL_Flip(screen);
  28.  
  29.         if(1000/FPS > SDL_GetTicks()-start) {
  30.             SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
  31.         }
  32.     }
  33.     SDL_Quit();
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement