Skip to content

Commit

Permalink
Fix high DPI rendering on MacOS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
binji committed Nov 15, 2018
1 parent 3a1c729 commit 1ac328b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/host-ui-imgui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ void HostUI::begin_frame() {

void HostUI::end_frame() {
ImGuiIO& io = ImGui::GetIO();
glViewport(0, 0, io.DisplaySize.x, io.DisplaySize.y);
glViewport(0, 0, io.DisplaySize.x * io.DisplayFramebufferScale.x,
io.DisplaySize.y * io.DisplayFramebufferScale.y);
glClearColor(0.1f, 0.1f, 0.1f, 1);
glClear(GL_COLOR_BUFFER_BIT);
ImGui::Render();
Expand Down
2 changes: 1 addition & 1 deletion src/host-ui-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void host_ui_event(struct HostUI* ui, union SDL_Event* event) {
(event->window.event == SDL_WINDOWEVENT_SHOWN ||
event->window.event == SDL_WINDOWEVENT_RESIZED)) {
int iw, ih;
SDL_GetWindowSize(ui->window, &iw, &ih);
SDL_GL_GetDrawableSize(ui->window, &iw, &ih);
f32 w = iw, h = ih;
f32 aspect = w / h;
f32 want_aspect = (f32)SCREEN_WIDTH / SCREEN_HEIGHT;
Expand Down

0 comments on commit 1ac328b

Please sign in to comment.