Skip to content

Commit 0503b40

Browse files
committed
fixed a window rescaling bug
1 parent dba9749 commit 0503b40

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

LuaSTG/Core/Graphics/SwapChain_OpenGL.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,33 +368,32 @@ namespace Core::Graphics
368368
bool SwapChain_OpenGL::present()
369369
{
370370
Vector2U wsize = m_window->getSize();
371-
Core::Vector2F scale_dim = Core::Vector2F((float) wsize.x / m_canvas_size.x, (float) wsize.y / m_canvas_size.y);
371+
Vector2F scale_dim = Vector2F((float) wsize.x / m_canvas_size.x, (float) wsize.y / m_canvas_size.y);
372372
float scale = std::min(scale_dim.x, scale_dim.y);
373373
Vector2F d;
374374

375375
if (scale_dim.x > scale_dim.y)
376376
{
377-
d.x = (wsize.x - scale * m_canvas_size.x) / 2;
377+
d.x = ((float)wsize.x - m_canvas_size.x * scale) * 0.5;
378378
d.y = 0;
379379
}
380380
else
381381
{
382382
d.x = 0;
383-
d.y = (wsize.y - scale * m_canvas_size.y) / 2;
383+
d.y = ((float)wsize.y - m_canvas_size.y * scale) * 0.5;
384384
}
385385

386386
glBindFramebuffer(GL_READ_FRAMEBUFFER, rdr_fbo);
387387
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
388+
glViewport(0, 0, wsize.x, wsize.y);
389+
glScissor(0, 0, wsize.x, wsize.y);
388390
glClearColor(0.f, 0.f, 0.f, 0.f);
389391
glClearDepth(1.f);
390392
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
391-
glViewport(0, 0, wsize.x, wsize.y);
392-
glScissor(0, 0, wsize.x, wsize.y);
393393

394394
glBlitFramebuffer(
395395
0, 0, m_canvas_size.x, m_canvas_size.y,
396-
(wsize.x - scale * (m_canvas_size.x + d.x)) / 2, (wsize.y + scale * (m_canvas_size.y + d.y)) / 2,
397-
(wsize.x + scale * (m_canvas_size.x + d.x)) / 2, (wsize.y - scale * (m_canvas_size.y + d.y)) / 2,
396+
d.x, scale * m_canvas_size.y + d.y, scale * m_canvas_size.x + d.x, d.y,
398397
GL_COLOR_BUFFER_BIT, GL_LINEAR
399398
);
400399

LuaSTG/Core/Graphics/Window_SDL.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "Core/Type.hpp"
55
#include "Core/i18n.hpp"
66
#include "SDL_events.h"
7-
#include "SDL_mouse.h"
87
#include "SDL_video.h"
98
#include "glad/gl.h"
109
#include "SDL.h"
@@ -154,6 +153,9 @@ namespace Core::Graphics
154153
int version = gladLoadGL((GLADloadfunc) SDL_GL_GetProcAddress);
155154
spdlog::info("[core] OpenGL {}.{}", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
156155
spdlog::info("[core] {}", (const char*)glGetString(GL_VERSION));
156+
GLint s;
157+
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s);
158+
spdlog::info("[core] max texture size: {}", s);
157159

158160
#ifndef __APPLE__
159161
#ifndef NDEBUG
@@ -454,6 +456,7 @@ namespace Core::Graphics
454456

455457
Vector2U Window_SDL::getSize()
456458
{
459+
SDL_GetWindowSize(sdl_window, (int*)&sdl_window_width, (int*)&sdl_window_height);
457460
return { sdl_window_width, sdl_window_height };
458461
}
459462
bool Window_SDL::setSize(Vector2U v)

LuaSTG/Core/Graphics/Window_SDL.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// #include "Platform/Monitor.hpp"
88
// #include "Platform/WindowSizeMoveController.hpp"
99
// #include "Platform/RuntimeLoader/DesktopWindowManager.hpp"
10-
#include <SDL_mouse.h>
1110
#include <SDL_rect.h>
1211
#include <SDL_surface.h>
1312
#include <SDL_video.h>

0 commit comments

Comments
 (0)