Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds fix for DPI scaling on backend_glfw_opengl #34

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libs/imgui/backends/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks
bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks);
void ImGui_ImplGlfw_Shutdown();
void ImGui_ImplGlfw_NewFrame();
void ImGui_ImplGlfw_NewFrame(float scale_x, float scale_y);

// GLFW callbacks install
// - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any.
Expand Down Expand Up @@ -993,7 +993,7 @@ static void ImGui_ImplGlfw_UpdateMonitors()
}
}

void ImGui_ImplGlfw_NewFrame()
extern "C" void ImGui_ImplGlfw_NewFrame(float scale_x,float scale_y)
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
Expand All @@ -1009,8 +1009,8 @@ void ImGui_ImplGlfw_NewFrame()
io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);

// fix(zig-gamedev)
bd->DpiScale.x = ceil(io.DisplayFramebufferScale.x);
bd->DpiScale.y = ceil(io.DisplayFramebufferScale.y);
bd->DpiScale.x = scale_x;
bd->DpiScale.y = scale_y;

if (bd->WantUpdateMonitors)
ImGui_ImplGlfw_UpdateMonitors();
Expand Down
2 changes: 1 addition & 1 deletion libs/imgui/backends/imgui_impl_glfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool in
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks);
IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(float scale_x, float scale_y);

// Emscripten related initialization phase methods (call after ImGui_ImplGlfw_InitForOpenGL)
#ifdef __EMSCRIPTEN__
Expand Down
6 changes: 3 additions & 3 deletions src/backend_glfw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ pub fn deinit() void {
ImGui_ImplGlfw_Shutdown();
}

pub fn newFrame() void {
ImGui_ImplGlfw_NewFrame();
pub fn newFrame(scale_x: f32, scale_y: f32) void {
ImGui_ImplGlfw_NewFrame(scale_x, scale_y);
}

// Those functions are defined in `imgui_impl_glfw.cpp`
// (they include few custom changes).
extern fn ImGui_ImplGlfw_InitForOther(window: *const anyopaque, install_callbacks: bool) bool;
extern fn ImGui_ImplGlfw_InitForOpenGL(window: *const anyopaque, install_callbacks: bool) bool;
extern fn ImGui_ImplGlfw_InitForVulkan(window: *const anyopaque, install_callbacks: bool) bool;
extern fn ImGui_ImplGlfw_NewFrame() void;
extern fn ImGui_ImplGlfw_NewFrame(scale_x: f32, scale_y: f32) void;
extern fn ImGui_ImplGlfw_Shutdown() void;
6 changes: 3 additions & 3 deletions src/backend_glfw_opengl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ pub fn deinit() void {
backend_glfw.deinit();
}

pub fn newFrame(fb_width: u32, fb_height: u32) void {
backend_glfw.newFrame();
pub fn newFrame(fb_width: u32, fb_height: u32, scale_x: f32, scale_y: f32) void {
backend_glfw.newFrame(scale_x, scale_y);
ImGui_ImplOpenGL3_NewFrame();

gui.io.setDisplaySize(@as(f32, @floatFromInt(fb_width)), @as(f32, @floatFromInt(fb_height)));
gui.io.setDisplayFramebufferScale(1.0, 1.0);
gui.io.setDisplayFramebufferScale(1, 1);

gui.newFrame();
}
Expand Down