Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Attempt at recreating an issue where resizing a borderless window not at 0,0 to display size breaks the sdl window
- // It works fine though so it's probably not sdl
- #include <SDL2/SDL.h>
- #undef main
- #include <iostream>
- #include <chrono>
- using namespace std::chrono;
- using namespace std::chrono_literals;
- SDL_Window* window = nullptr;
- SDL_Renderer* renderer = nullptr;
- void printMousePositionFor5Seconds()
- {
- auto begin = steady_clock::now();
- while (steady_clock::now() - begin < 5s)
- {
- SDL_Event evt;
- SDL_PumpEvents();
- while (SDL_PollEvent(&evt))
- {
- if (evt.type == SDL_MOUSEMOTION)
- {
- std::cout << "Mouse moved to: " << evt.motion.x << ", " << evt.motion.y << std::endl;
- }
- }
- SDL_RenderClear(renderer);
- SDL_RenderPresent(renderer);
- SDL_Delay(50);
- }
- }
- int main()
- {
- SDL_Init(SDL_INIT_VIDEO);
- (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8));
- (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8));
- (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8));
- (SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0));
- (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24));
- (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1));
- (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4));
- window = SDL_CreateWindow(
- "SDL2Test",
- 120,
- 120,
- 640,
- 480,
- SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN
- );
- auto index = SDL_GetWindowDisplayIndex(window);
- SDL_Rect rect{};
- SDL_GetDisplayBounds(index, &rect);
- SDL_SetWindowSize(window, rect.w / 2, rect.h / 2);
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
- printMousePositionFor5Seconds();
- SDL_SetWindowFullscreen(window, 0);
- SDL_SetWindowSize(window, rect.w, rect.h);
- SDL_SetWindowBordered(window, SDL_FALSE);
- printMousePositionFor5Seconds();
- SDL_DestroyWindow(window);
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement