diff options
| author | Andre Weissflog <floooh@gmail.com> | 2025-08-29 17:00:38 +0200 |
|---|---|---|
| committer | Andre Weissflog <floooh@gmail.com> | 2025-08-29 17:00:38 +0200 |
| commit | 19f2f321f27923076aff3b7af2192dcb6c56ac06 (patch) | |
| tree | 9b37318c1d90bcaf2b517bd87554c15bee9e2684 | |
| parent | 8a2990ab7d9d45ac70234bb8e1782fb193fde13c (diff) | |
sokol_imgui.h: fix font density issue (by properly setting io.DisplayFramebufferScale
| -rw-r--r-- | util/sokol_imgui.h | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/util/sokol_imgui.h b/util/sokol_imgui.h index 935e7708..1aa48981 100644 --- a/util/sokol_imgui.h +++ b/util/sokol_imgui.h @@ -2916,6 +2916,8 @@ SOKOL_API_IMPL void simgui_new_frame(const simgui_frame_desc_t* desc) { ImGuiIO* io = _simgui_imgui_get_io(); io->DisplaySize.x = ((float)desc->width) / _simgui.cur_dpi_scale; io->DisplaySize.y = ((float)desc->height) / _simgui.cur_dpi_scale; + io->DisplayFramebufferScale.x = _simgui.cur_dpi_scale; + io->DisplayFramebufferScale.y = _simgui.cur_dpi_scale; io->DeltaTime = (float)desc->delta_time; #if !defined(SOKOL_IMGUI_NO_SOKOL_APP) if (io->WantTextInput && !sapp_keyboard_shown()) { @@ -3032,9 +3034,8 @@ SOKOL_API_IMPL void simgui_render(void) { } // render the ImGui command list - const float dpi_scale = _simgui.cur_dpi_scale; - const int fb_width = (int) (io->DisplaySize.x * dpi_scale); - const int fb_height = (int) (io->DisplaySize.y * dpi_scale); + const int fb_width = (int) (io->DisplaySize.x * draw_data->FramebufferScale.x); + const int fb_height = (int) (io->DisplaySize.y * draw_data->FramebufferScale.y); sg_apply_viewport(0, 0, fb_width, fb_height, true); sg_apply_scissor_rect(0, 0, fb_width, fb_height, true); @@ -3087,10 +3088,10 @@ SOKOL_API_IMPL void simgui_render(void) { bind.vertex_buffer_offsets[0] = vb_offset + (int)(pcmd->VtxOffset * sizeof(ImDrawVert)); sg_apply_bindings(&bind); } - const int scissor_x = (int) (pcmd->ClipRect.x * dpi_scale); - const int scissor_y = (int) (pcmd->ClipRect.y * dpi_scale); - const int scissor_w = (int) ((pcmd->ClipRect.z - pcmd->ClipRect.x) * dpi_scale); - const int scissor_h = (int) ((pcmd->ClipRect.w - pcmd->ClipRect.y) * dpi_scale); + const int scissor_x = (int) (pcmd->ClipRect.x * draw_data->FramebufferScale.x); + const int scissor_y = (int) (pcmd->ClipRect.y * draw_data->FramebufferScale.y); + const int scissor_w = (int) ((pcmd->ClipRect.z - pcmd->ClipRect.x) * draw_data->FramebufferScale.x); + const int scissor_h = (int) ((pcmd->ClipRect.w - pcmd->ClipRect.y) * draw_data->FramebufferScale.y); sg_apply_scissor_rect(scissor_x, scissor_y, scissor_w, scissor_h, true); sg_draw((int)pcmd->IdxOffset, (int)pcmd->ElemCount, 1); } |