Fix viewport for retina displays
This commit is contained in:
1 parent
de99849471
commit
54e2da3778
2 files changed
+6
-7
No files matched your search
@@ -363,7 +363,7 @@ public final class ImGuiImplGl3 {
|
|||||||
// Setup viewport, orthographic projection matrix
|
// Setup viewport, orthographic projection matrix
|
||||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
|
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
|
||||||
// DisplayPos is (0,0) for single viewport apps.
|
// DisplayPos is (0,0) for single viewport apps.
|
||||||
glViewport(0, 0, (int) displaySize.x, (int) displaySize.y);
|
glViewport(0, 0, (int) (displaySize.x * framebufferScale.x), (int) (displaySize.y * framebufferScale.y));
|
||||||
final float left = displayPos.x;
|
final float left = displayPos.x;
|
||||||
final float right = displayPos.x + displaySize.x;
|
final float right = displayPos.x + displaySize.x;
|
||||||
final float top = displayPos.y;
|
final float top = displayPos.y;
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ public class ImGuiImplGlfw {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMousePosAndButtons(final float scaleX, final float scaleY) {
|
private void updateMousePosAndButtons() {
|
||||||
final ImGuiIO io = ImGui.getIO();
|
final ImGuiIO io = ImGui.getIO();
|
||||||
|
|
||||||
for (int i = 0; i < ImGuiMouseButton.COUNT; i++) {
|
for (int i = 0; i < ImGuiMouseButton.COUNT; i++) {
|
||||||
@@ -297,7 +297,7 @@ public class ImGuiImplGlfw {
|
|||||||
glfwSetCursorPos(windowPtr, mousePosBackup.x, mousePosBackup.y);
|
glfwSetCursorPos(windowPtr, mousePosBackup.x, mousePosBackup.y);
|
||||||
} else {
|
} else {
|
||||||
glfwGetCursorPos(windowPtr, cursorPosX, cursorPosY);
|
glfwGetCursorPos(windowPtr, cursorPosX, cursorPosY);
|
||||||
io.setMousePos((float) cursorPosX[0] * scaleX, (float) cursorPosY[0] * scaleY);
|
io.setMousePos((float) cursorPosX[0], (float) cursorPosY[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,11 +400,10 @@ public class ImGuiImplGlfw {
|
|||||||
glfwGetWindowSize(windowPtr, winWidth, winHeight);
|
glfwGetWindowSize(windowPtr, winWidth, winHeight);
|
||||||
glfwGetFramebufferSize(windowPtr, fbWidth, fbHeight);
|
glfwGetFramebufferSize(windowPtr, fbWidth, fbHeight);
|
||||||
|
|
||||||
final float scaleX = (float) fbWidth[0] / winWidth[0];
|
|
||||||
final float scaleY = (float) fbHeight[0] / winHeight[0];
|
|
||||||
|
|
||||||
io.setDisplaySize((float) winWidth[0], (float) winHeight[0]);
|
io.setDisplaySize((float) winWidth[0], (float) winHeight[0]);
|
||||||
if (winWidth[0] > 0 && winHeight[0] > 0) {
|
if (winWidth[0] > 0 && winHeight[0] > 0) {
|
||||||
|
final float scaleX = (float) fbWidth[0] / winWidth[0];
|
||||||
|
final float scaleY = (float) fbHeight[0] / winHeight[0];
|
||||||
io.setDisplayFramebufferScale(scaleX, scaleY);
|
io.setDisplayFramebufferScale(scaleX, scaleY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,7 +411,7 @@ public class ImGuiImplGlfw {
|
|||||||
io.setDeltaTime(time > 0.0 ? (float) (currentTime - time) : 1.0f / 60.0f);
|
io.setDeltaTime(time > 0.0 ? (float) (currentTime - time) : 1.0f / 60.0f);
|
||||||
time = currentTime;
|
time = currentTime;
|
||||||
|
|
||||||
updateMousePosAndButtons(scaleX, scaleY);
|
updateMousePosAndButtons();
|
||||||
updateMouseCursor();
|
updateMouseCursor();
|
||||||
updateGamepads();
|
updateGamepads();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user