diff --git a/GUI/OpenGL/MiniGL.cpp b/GUI/OpenGL/MiniGL.cpp index e5e66d5d..92c5c193 100644 --- a/GUI/OpenGL/MiniGL.cpp +++ b/GUI/OpenGL/MiniGL.cpp @@ -34,6 +34,9 @@ MiniGL::DestroyFct MiniGL::destroyfunc = nullptr; void (*MiniGL::exitfunc)(void) = NULL; int MiniGL::m_width = 0; int MiniGL::m_height = 0; +int MiniGL::m_windowWidth = 0; +int MiniGL::m_windowHeight = 0; +Real MiniGL::m_devicePixelRatio = 1.0f; Quaternionr MiniGL::m_rotation; Real MiniGL::m_zoom = 1.0; Vector3r MiniGL::m_translation; @@ -686,7 +689,9 @@ void MiniGL::viewport () { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glfwGetFramebufferSize(m_glfw_window, &m_width, &m_height); + getWindowSize(m_windowWidth, m_windowHeight); + glfwGetFramebufferSize(m_glfw_window, &m_width, &m_height); + m_devicePixelRatio = static_cast(m_width) / static_cast(m_windowWidth); glViewport (0, 0, m_width, m_height); setProjectionMatrix (m_width, m_height); @@ -787,8 +792,8 @@ void MiniGL::enableScreenShader(const Vector3r& color) { Shader& shader = m_shader_screen; shader.begin(); - glUniform1f(shader.getUniform("width"), static_cast(m_width)); - glUniform1f(shader.getUniform("height"), static_cast(m_height)); + glUniform1f(shader.getUniform("width"), static_cast(m_windowWidth)); + glUniform1f(shader.getUniform("height"), static_cast(m_windowHeight)); glUniform3fv(shader.getUniform("color"), 1, &color(0)); } @@ -956,7 +961,11 @@ void MiniGL::unproject(const int x, const int y, Vector3r &pos) glGetIntegerv(GL_VIEWPORT, viewport); unproject( - Vector3r(static_cast(x), static_cast(viewport[3] - y), static_cast(znear)), + Vector3r( + static_cast(x) * m_devicePixelRatio, + static_cast(viewport[3]) - static_cast(y) * m_devicePixelRatio, + static_cast(znear) + ), pos ); } diff --git a/GUI/OpenGL/MiniGL.h b/GUI/OpenGL/MiniGL.h index 68e92d91..70219be2 100644 --- a/GUI/OpenGL/MiniGL.h +++ b/GUI/OpenGL/MiniGL.h @@ -80,6 +80,9 @@ namespace SPH static std::vector m_mouseWheelFct; static int m_width; static int m_height; + static int m_windowWidth; + static int m_windowHeight; + static Real m_devicePixelRatio; static Vector3r m_translation; static Quaternionr m_rotation; static Real m_zoom; @@ -199,6 +202,7 @@ namespace SPH static int getWidth() { return m_width; } static int getHeight() { return m_height; } + static Real getDevicePixelRatio() { return m_devicePixelRatio; } static int getDrawMode() { return drawMode; } static void setDrawMode(int val) { drawMode = val; } diff --git a/GUI/OpenGL/Selection.h b/GUI/OpenGL/Selection.h index d5f82897..c2e86480 100644 --- a/GUI/OpenGL/Selection.h +++ b/GUI/OpenGL/Selection.h @@ -42,10 +42,10 @@ namespace SPH int itop = ip1y > ip2y ? ip1y : ip2y; int ibottom = ip1y < ip2y ? ip1y : ip2y; - float left = (float)ileft; - float right = (float)iright; - float top = (float)itop; - float bottom = (float)ibottom; + float left = (float)ileft * MiniGL::getDevicePixelRatio(); + float right = (float)iright * MiniGL::getDevicePixelRatio(); + float top = (float)itop * MiniGL::getDevicePixelRatio(); + float bottom = (float)ibottom * MiniGL::getDevicePixelRatio(); if (left != right && top != bottom) {