Advertisement
Guest User

sdgsfdsfdg

a guest
Dec 16th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. #ifdef __cplusplus
  2.     #include <cstdlib>
  3. #else
  4.     #include <stdlib.h>
  5. #endif
  6.  
  7. #include <SDL/SDL.h>
  8.  
  9. int main ( int argc, char** argv )
  10. {
  11.     // initialize SDL video
  12.     if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  13.     {
  14.         printf( "Unable to init SDL: %s\n", SDL_GetError() );
  15.         return 1;
  16.     }
  17.  
  18.     // make sure SDL cleans up before exit
  19.     atexit(SDL_Quit);
  20.  
  21.     // create a new window
  22.     SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16,
  23.                                            SDL_HWSURFACE|SDL_DOUBLEBUF);
  24.     if ( !screen )
  25.     {
  26.         printf("Unable to set 640x480 video: %s\n", SDL_GetError());
  27.         return 1;
  28.     }
  29.  
  30.    
  31.    
  32.    
  33.     // load an image
  34.     SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
  35.     if (!bmp)
  36.     {
  37.         printf("Unable to load bitmap: %s\n", SDL_GetError());
  38.         return 1;
  39.     }
  40.  
  41.     // centre the bitmap on screen
  42.     SDL_Rect dstrect;
  43.     dstrect.x = (screen->w - bmp->w) / 2;
  44.     dstrect.y = (screen->h - bmp->h) / 2;
  45.  
  46.     // program main loop
  47.     bool done = false;
  48.     while (!done)
  49.     {
  50.         // message processing loop
  51.         SDL_Event event;
  52.         while (SDL_PollEvent(&event))
  53.         {
  54.             // check for messages
  55.             switch (event.type)
  56.             {
  57.                 // exit if the window is closed
  58.             case SDL_QUIT:
  59.                 done = true;
  60.                 break;
  61.  
  62.                 // check for keypresses
  63.             case SDL_KEYDOWN:
  64.                 {
  65.                     // exit if ESCAPE is pressed
  66.                     if (event.key.keysym.sym == SDLK_ESCAPE)
  67.                         done = true;
  68.                     break;
  69.                 }
  70.             } // end switch
  71.         } // end of message processing
  72.  
  73.         // DRAWING STARTS HERE
  74.  
  75.         // clear screen
  76.         SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
  77.  
  78.         // draw bitmap
  79.            dstrect.x  +=2;
  80.         SDL_BlitSurface(bmp, 0, screen, &dstrect);
  81.  
  82.         // DRAWING ENDS HERE
  83.  
  84.         // finally, update the screen :)
  85.         SDL_Flip(screen);
  86.     } // end main loop
  87.     SDL_Delay(100);
  88.     // free loaded bitmap
  89.     SDL_FreeSurface(bmp);
  90.  
  91.  
  92.  
  93.     // all is well ;)
  94.     printf("Exited cleanly\n");
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement