Advertisement
Guest User

Untitled

a guest
Jul 14th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. // Attempt at recreating an issue where resizing a borderless window not at 0,0 to display size breaks the sdl window
  2. // It works fine though so it's probably not sdl
  3.  
  4. #include <SDL2/SDL.h>
  5. #undef main
  6.  
  7. #include <iostream>
  8. #include <chrono>
  9.  
  10. using namespace std::chrono;
  11. using namespace std::chrono_literals;
  12.  
  13. SDL_Window* window = nullptr;
  14. SDL_Renderer* renderer = nullptr;
  15.  
  16.  
  17. void printMousePositionFor5Seconds()
  18. {
  19.     auto begin = steady_clock::now();
  20.     while (steady_clock::now() - begin < 5s)
  21.     {
  22.         SDL_Event evt;
  23.  
  24.         SDL_PumpEvents();
  25.         while (SDL_PollEvent(&evt))
  26.         {
  27.             if (evt.type == SDL_MOUSEMOTION)
  28.             {
  29.                 std::cout << "Mouse moved to: " << evt.motion.x << ", " << evt.motion.y << std::endl;
  30.             }
  31.         }
  32.  
  33.         SDL_RenderClear(renderer);
  34.         SDL_RenderPresent(renderer);
  35.  
  36.         SDL_Delay(50);
  37.     }
  38. }
  39.  
  40. int main()
  41. {
  42.     SDL_Init(SDL_INIT_VIDEO);
  43.  
  44.     (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8));
  45.     (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8));
  46.     (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8));
  47.     (SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0));
  48.     (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24));
  49.     (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1));
  50.     (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4));
  51.  
  52.     window = SDL_CreateWindow(
  53.         "SDL2Test",
  54.         120,
  55.         120,
  56.         640,
  57.         480,
  58.         SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN
  59.     );
  60.  
  61.     auto index = SDL_GetWindowDisplayIndex(window);
  62.     SDL_Rect rect{};
  63.     SDL_GetDisplayBounds(index, &rect);
  64.     SDL_SetWindowSize(window, rect.w / 2, rect.h / 2);
  65.  
  66.     renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
  67.     SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
  68.  
  69.     printMousePositionFor5Seconds();
  70.  
  71.     SDL_SetWindowFullscreen(window, 0);
  72.     SDL_SetWindowSize(window, rect.w, rect.h);
  73.     SDL_SetWindowBordered(window, SDL_FALSE);
  74.  
  75.     printMousePositionFor5Seconds();
  76.  
  77.     SDL_DestroyWindow(window);
  78.     SDL_Quit();
  79.  
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement