Skip to content

Commit 1ac328b

Browse files
committed
Fix high DPI rendering on MacOS
According to the SDL2 docs, `SDL_GetWindowSize` returns the client window size in screen coordinates, `SDL_GL_GetDrawableSize` returns the size in pixels. This change makes sure the `glViewport` calls always use pixels.
1 parent 3a1c729 commit 1ac328b

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/host-ui-imgui.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ void HostUI::begin_frame() {
288288

289289
void HostUI::end_frame() {
290290
ImGuiIO& io = ImGui::GetIO();
291-
glViewport(0, 0, io.DisplaySize.x, io.DisplaySize.y);
291+
glViewport(0, 0, io.DisplaySize.x * io.DisplayFramebufferScale.x,
292+
io.DisplaySize.y * io.DisplayFramebufferScale.y);
292293
glClearColor(0.1f, 0.1f, 0.1f, 1);
293294
glClear(GL_COLOR_BUFFER_BIT);
294295
ImGui::Render();

src/host-ui-simple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void host_ui_event(struct HostUI* ui, union SDL_Event* event) {
104104
(event->window.event == SDL_WINDOWEVENT_SHOWN ||
105105
event->window.event == SDL_WINDOWEVENT_RESIZED)) {
106106
int iw, ih;
107-
SDL_GetWindowSize(ui->window, &iw, &ih);
107+
SDL_GL_GetDrawableSize(ui->window, &iw, &ih);
108108
f32 w = iw, h = ih;
109109
f32 aspect = w / h;
110110
f32 want_aspect = (f32)SCREEN_WIDTH / SCREEN_HEIGHT;

0 commit comments

Comments
 (0)