From 0503b4061a1b024255c937755c0fd8e43e248d8f Mon Sep 17 00:00:00 2001 From: Kalei Alma Date: Mon, 22 Jul 2024 08:34:05 -0700 Subject: [PATCH] fixed a window rescaling bug --- LuaSTG/Core/Graphics/SwapChain_OpenGL.cpp | 13 ++++++------- LuaSTG/Core/Graphics/Window_SDL.cpp | 5 ++++- LuaSTG/Core/Graphics/Window_SDL.hpp | 1 - 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/LuaSTG/Core/Graphics/SwapChain_OpenGL.cpp b/LuaSTG/Core/Graphics/SwapChain_OpenGL.cpp index 3a4e110..c00b211 100644 --- a/LuaSTG/Core/Graphics/SwapChain_OpenGL.cpp +++ b/LuaSTG/Core/Graphics/SwapChain_OpenGL.cpp @@ -368,33 +368,32 @@ namespace Core::Graphics bool SwapChain_OpenGL::present() { Vector2U wsize = m_window->getSize(); - Core::Vector2F scale_dim = Core::Vector2F((float) wsize.x / m_canvas_size.x, (float) wsize.y / m_canvas_size.y); + Vector2F scale_dim = Vector2F((float) wsize.x / m_canvas_size.x, (float) wsize.y / m_canvas_size.y); float scale = std::min(scale_dim.x, scale_dim.y); Vector2F d; if (scale_dim.x > scale_dim.y) { - d.x = (wsize.x - scale * m_canvas_size.x) / 2; + d.x = ((float)wsize.x - m_canvas_size.x * scale) * 0.5; d.y = 0; } else { d.x = 0; - d.y = (wsize.y - scale * m_canvas_size.y) / 2; + d.y = ((float)wsize.y - m_canvas_size.y * scale) * 0.5; } glBindFramebuffer(GL_READ_FRAMEBUFFER, rdr_fbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glViewport(0, 0, wsize.x, wsize.y); + glScissor(0, 0, wsize.x, wsize.y); glClearColor(0.f, 0.f, 0.f, 0.f); glClearDepth(1.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glViewport(0, 0, wsize.x, wsize.y); - glScissor(0, 0, wsize.x, wsize.y); glBlitFramebuffer( 0, 0, m_canvas_size.x, m_canvas_size.y, - (wsize.x - scale * (m_canvas_size.x + d.x)) / 2, (wsize.y + scale * (m_canvas_size.y + d.y)) / 2, - (wsize.x + scale * (m_canvas_size.x + d.x)) / 2, (wsize.y - scale * (m_canvas_size.y + d.y)) / 2, + d.x, scale * m_canvas_size.y + d.y, scale * m_canvas_size.x + d.x, d.y, GL_COLOR_BUFFER_BIT, GL_LINEAR ); diff --git a/LuaSTG/Core/Graphics/Window_SDL.cpp b/LuaSTG/Core/Graphics/Window_SDL.cpp index b19a3b2..bec8875 100644 --- a/LuaSTG/Core/Graphics/Window_SDL.cpp +++ b/LuaSTG/Core/Graphics/Window_SDL.cpp @@ -4,7 +4,6 @@ #include "Core/Type.hpp" #include "Core/i18n.hpp" #include "SDL_events.h" -#include "SDL_mouse.h" #include "SDL_video.h" #include "glad/gl.h" #include "SDL.h" @@ -154,6 +153,9 @@ namespace Core::Graphics int version = gladLoadGL((GLADloadfunc) SDL_GL_GetProcAddress); spdlog::info("[core] OpenGL {}.{}", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version)); spdlog::info("[core] {}", (const char*)glGetString(GL_VERSION)); + GLint s; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s); + spdlog::info("[core] max texture size: {}", s); #ifndef __APPLE__ #ifndef NDEBUG @@ -454,6 +456,7 @@ namespace Core::Graphics Vector2U Window_SDL::getSize() { + SDL_GetWindowSize(sdl_window, (int*)&sdl_window_width, (int*)&sdl_window_height); return { sdl_window_width, sdl_window_height }; } bool Window_SDL::setSize(Vector2U v) diff --git a/LuaSTG/Core/Graphics/Window_SDL.hpp b/LuaSTG/Core/Graphics/Window_SDL.hpp index c0e53da..862e492 100644 --- a/LuaSTG/Core/Graphics/Window_SDL.hpp +++ b/LuaSTG/Core/Graphics/Window_SDL.hpp @@ -7,7 +7,6 @@ // #include "Platform/Monitor.hpp" // #include "Platform/WindowSizeMoveController.hpp" // #include "Platform/RuntimeLoader/DesktopWindowManager.hpp" -#include #include #include #include