Advertisement
Guest User

Untitled

a guest
Sep 1st, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <SDL.h>
  3.  
  4. SDL_Surface *surface;
  5. SDL_Window *window;
  6. SDL_Joystick *joystick;
  7.  
  8. int main(int argc, char *argv[]) {
  9.    
  10.     if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0) {
  11.         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
  12.         return 1;
  13.     }
  14.    
  15.     printf("%i joystick(s) found.\n", SDL_NumJoysticks());
  16.     printf("The names of the joysticks are:\n");
  17.  
  18.     int i;
  19.  
  20.     for (i = 0; i < SDL_NumJoysticks(); i++) {
  21.         joystick = SDL_JoystickOpen(i);
  22.         printf("%s\n", SDL_JoystickName(joystick));
  23.     }
  24.    
  25.     printf("Video Driver: %s\n", SDL_GetCurrentVideoDriver());
  26.    
  27.     window = SDL_CreateWindow(
  28.     "An SDL2 window",                  //    window title
  29.     SDL_WINDOWPOS_UNDEFINED,           //    initial x position
  30.     SDL_WINDOWPOS_UNDEFINED,           //    initial y position
  31.     640,                               //    width, in pixels
  32.     480,                               //    height, in pixels
  33.     SDL_WINDOW_SHOWN|SDL_WINDOW_BORDERLESS);
  34.  
  35.     if(window==NULL) {
  36.         // In the event that the window could not be made...
  37.         fprintf(stderr, "Could not create window: %s\n", SDL_GetError());
  38.         return 1;
  39.     }
  40.    
  41.     SDL_JoystickEventState(SDL_ENABLE);
  42.     SDL_Event event;
  43.    
  44.     int running = 1;
  45.    
  46.     while (running) {
  47.         while(SDL_PollEvent(&event)) {
  48.             switch(event.type) {
  49.                 case SDL_KEYUP:
  50.                 case SDL_KEYDOWN:
  51.                 case SDL_JOYAXISMOTION:
  52.                 case SDL_JOYHATMOTION:
  53.                 case SDL_JOYBUTTONUP:
  54.                 case SDL_JOYBUTTONDOWN:
  55.                     printf("Input Detected\n");
  56.                     printf("Event State: %d\n", event.jbutton.state);
  57.                     break;
  58.  
  59.                 case SDL_QUIT:
  60.                     running = 0;
  61.                     break;
  62.            
  63.                 default:
  64.                     break;
  65.             }
  66.            
  67.             switch (event.key.keysym.sym) {
  68.                 case SDLK_ESCAPE:
  69.                     running = 0;
  70.                     break;
  71.            
  72.                 default:
  73.                     break;
  74.             }
  75.         }
  76.     }
  77.    
  78.     SDL_DestroyWindow(window);
  79.     SDL_Quit();
  80.    
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement