SHARE
TWEET

Untitled

a guest Aug 16th, 2018 11 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //2011-0301
  2. //#include <string.h>
  3. #include <SDL2/SDL.h>
  4.  
  5. //const int SCREEN_WIDTH = 1280;
  6. //const int SCREEN_HEIGHT = 720;
  7. #define SCREEN_WIDTH 1280
  8. #define SCREEN_HEIGHT 720
  9.  
  10. int main(int argc, char **argv) {
  11.     bool quit = false;
  12.  
  13.     if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
  14.         printf("SDL init failed: %s\n", SDL_GetError());
  15.         return 1;
  16.     }
  17.  
  18.     SDL_Window* window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
  19.     SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
  20.     SDL_Texture * texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, SCREEN_WIDTH, SCREEN_HEIGHT);
  21.     Uint32 pixels[SCREEN_WIDTH * SCREEN_HEIGHT];
  22.     memset(pixels, 255, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
  23.  
  24.     int j;
  25.     for (j = 0; j < SDL_NumJoysticks(); j++) {
  26.         if (SDL_JoystickOpen(j) == NULL) {
  27.             printf("SDL_JoystickOpen: %s\n", SDL_GetError());
  28.             SDL_Quit();
  29.             return 1;
  30.         }
  31.     }
  32.  
  33.     while (!quit) {
  34.         SDL_UpdateTexture(texture, NULL, pixels, SCREEN_WIDTH * 4);
  35.  
  36.         SDL_Event event;
  37.         while (SDL_PollEvent(&event)) {
  38.             //printf("event.type=%d; fingerdown=%d; fingermotion=%d", event.type, SDL_FINGERDOWN, SDL_FINGERMOTION);
  39.             if (event.type == SDL_FINGERDOWN || event.type == SDL_FINGERMOTION) {
  40.                 int touchX = event.tfinger.x * SCREEN_WIDTH;
  41.                 int touchY = event.tfinger.y * SCREEN_HEIGHT;
  42.                 pixels[touchY * SCREEN_WIDTH + touchX] = 0;
  43.             } else if (event.type == SDL_JOYBUTTONDOWN) {
  44.                 if(event.jbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
  45.                     quit = true;
  46.             }
  47.         }
  48.  
  49.         SDL_RenderClear(renderer);
  50.         SDL_RenderCopy(renderer, texture, NULL, NULL);
  51.         SDL_RenderPresent(renderer);
  52.         //SDL_Delay(25);
  53.     }
  54.  
  55.     //delete[] pixels;
  56.     SDL_DestroyTexture(texture);
  57.     SDL_DestroyRenderer(renderer);
  58.     SDL_DestroyWindow(window);
  59.     SDL_Quit();
  60.  
  61.     return 0;
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top