Skip to content

Commit 54e2da3

Browse files
committed
Fix viewport for retina displays
1 parent de99849 commit 54e2da3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

imgui-lwjgl3/src/main/java/imgui/gl3/ImGuiImplGl3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ private void bind() {
363363
// Setup viewport, orthographic projection matrix
364364
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
365365
// DisplayPos is (0,0) for single viewport apps.
366-
glViewport(0, 0, (int) displaySize.x, (int) displaySize.y);
366+
glViewport(0, 0, (int) (displaySize.x * framebufferScale.x), (int) (displaySize.y * framebufferScale.y));
367367
final float left = displayPos.x;
368368
final float right = displayPos.x + displaySize.x;
369369
final float top = displayPos.y;

imgui-lwjgl3/src/main/java/imgui/glfw/ImGuiImplGlfw.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public void dispose() {
279279
}
280280
}
281281

282-
private void updateMousePosAndButtons(final float scaleX, final float scaleY) {
282+
private void updateMousePosAndButtons() {
283283
final ImGuiIO io = ImGui.getIO();
284284

285285
for (int i = 0; i < ImGuiMouseButton.COUNT; i++) {
@@ -297,7 +297,7 @@ private void updateMousePosAndButtons(final float scaleX, final float scaleY) {
297297
glfwSetCursorPos(windowPtr, mousePosBackup.x, mousePosBackup.y);
298298
} else {
299299
glfwGetCursorPos(windowPtr, cursorPosX, cursorPosY);
300-
io.setMousePos((float) cursorPosX[0] * scaleX, (float) cursorPosY[0] * scaleY);
300+
io.setMousePos((float) cursorPosX[0], (float) cursorPosY[0]);
301301
}
302302
}
303303
}
@@ -400,19 +400,18 @@ public void newFrame() {
400400
glfwGetWindowSize(windowPtr, winWidth, winHeight);
401401
glfwGetFramebufferSize(windowPtr, fbWidth, fbHeight);
402402

403-
final float scaleX = (float) fbWidth[0] / winWidth[0];
404-
final float scaleY = (float) fbHeight[0] / winHeight[0];
405-
406403
io.setDisplaySize((float) winWidth[0], (float) winHeight[0]);
407404
if (winWidth[0] > 0 && winHeight[0] > 0) {
405+
final float scaleX = (float) fbWidth[0] / winWidth[0];
406+
final float scaleY = (float) fbHeight[0] / winHeight[0];
408407
io.setDisplayFramebufferScale(scaleX, scaleY);
409408
}
410409

411410
final double currentTime = glfwGetTime();
412411
io.setDeltaTime(time > 0.0 ? (float) (currentTime - time) : 1.0f / 60.0f);
413412
time = currentTime;
414413

415-
updateMousePosAndButtons(scaleX, scaleY);
414+
updateMousePosAndButtons();
416415
updateMouseCursor();
417416
updateGamepads();
418417
}

0 commit comments

Comments
 (0)