Advertisement
Guest User

GreatShow

a guest
Nov 23rd, 2014
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. /**GreatShow: silly program that repeatedly displays a bunch
  2.  * of images to the screen.
  3.  * WARNING: DON'T RUN THIS IF YOU HAVE PHOTOSENSITIVE EPILEPSY
  4.  *
  5.  * I'm not a doctor and I have no idea if this can trigger a
  6.  * seizure.  In Elementary it was supposed to have been used
  7.  * to kill a guy with epilepsy so uh just be careful.
  8.  *
  9.  * Copyright Patrick Simmons, license is GPL 3.0
  10. */
  11.  
  12. #include <sys/types.h>
  13. #include <dirent.h>
  14. #include <string>
  15. #include <vector>
  16.  
  17. #include <SDL/SDL.h>
  18. #include <SDL/SDL_image.h>
  19.  
  20. int main(int argc, char** argv)
  21. {
  22.      //Boilerplate init
  23.      SDL_Init(SDL_INIT_EVERYTHING);
  24.  
  25.      //Get current display mode
  26.      const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
  27.  
  28.      //Set fullscreen with current display mode
  29.      SDL_Surface* screen = SDL_SetVideoMode(videoInfo->current_w,videoInfo->current_h,0,SDL_FULLSCREEN);
  30.  
  31.      
  32.      //Read in images to display
  33.      std::vector<SDL_Surface*> images;
  34.      DIR* dirp = opendir(".");
  35.      dirent* cur = readdir(dirp);
  36.      while(cur)
  37.      {
  38.           std::string x = cur->d_name;
  39.           if(x.length()<4)
  40.           {
  41.                cur = readdir(dirp);
  42.                continue;
  43.           }
  44.          
  45.           x = x.substr(x.length()-4,4);
  46.           if(x==".png" || x==".jpg" || x==".gif")
  47.                images.push_back(IMG_Load(cur->d_name));
  48.  
  49.           cur = readdir(dirp);
  50.      }
  51.  
  52.      //Quickly flash images on screen
  53.      //No way to quit program btw.
  54.      while(true)
  55.      {
  56.           for(int i=0; i<images.size(); i++)
  57.           {
  58.                SDL_BlitSurface(images[i],NULL,screen,NULL);
  59.                SDL_Flip(screen);
  60.           }
  61.  
  62.           //Quit when user presses any key
  63.           SDL_Event event;
  64.           if(SDL_PollEvent(&event))
  65.                if(event.type==SDL_KEYDOWN)
  66.                     break;
  67.      }
  68.  
  69.      //Boilerplate quit
  70.      SDL_Quit();
  71.      return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement