@@ -34,6 +34,9 @@ MiniGL::DestroyFct MiniGL::destroyfunc = nullptr;
34
34
void (*MiniGL::exitfunc)(void ) = NULL ;
35
35
int MiniGL::m_width = 0 ;
36
36
int MiniGL::m_height = 0 ;
37
+ int MiniGL::m_windowWidth = 0 ;
38
+ int MiniGL::m_windowHeight = 0 ;
39
+ Real MiniGL::m_devicePixelRatio = 1 .0f ;
37
40
Quaternionr MiniGL::m_rotation;
38
41
Real MiniGL::m_zoom = 1.0 ;
39
42
Vector3r MiniGL::m_translation;
@@ -686,7 +689,9 @@ void MiniGL::viewport ()
686
689
{
687
690
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
688
691
689
- glfwGetFramebufferSize (m_glfw_window, &m_width, &m_height);
692
+ glfwGetFramebufferSize (m_glfw_window, &m_width, &m_height);
693
+ getWindowSize (m_windowWidth, m_windowHeight);
694
+ m_devicePixelRatio = static_cast <Real>(m_width) / static_cast <Real>(m_windowWidth);
690
695
glViewport (0 , 0 , m_width, m_height);
691
696
setProjectionMatrix (m_width, m_height);
692
697
@@ -787,8 +792,8 @@ void MiniGL::enableScreenShader(const Vector3r& color)
787
792
{
788
793
Shader& shader = m_shader_screen;
789
794
shader.begin ();
790
- glUniform1f (shader.getUniform (" width" ), static_cast <Real>(m_width ));
791
- glUniform1f (shader.getUniform (" height" ), static_cast <Real>(m_height ));
795
+ glUniform1f (shader.getUniform (" width" ), static_cast <Real>(m_windowWidth ));
796
+ glUniform1f (shader.getUniform (" height" ), static_cast <Real>(m_windowHeight ));
792
797
glUniform3fv (shader.getUniform (" color" ), 1 , &color (0 ));
793
798
}
794
799
@@ -956,7 +961,11 @@ void MiniGL::unproject(const int x, const int y, Vector3r &pos)
956
961
glGetIntegerv (GL_VIEWPORT, viewport);
957
962
958
963
unproject (
959
- Vector3r (static_cast <Real>(x), static_cast <Real>(viewport[3 ] - y), static_cast <Real>(znear)),
964
+ Vector3r (
965
+ static_cast <Real>(x) * m_devicePixelRatio,
966
+ static_cast <Real>(viewport[3 ]) - static_cast <Real>(y) * m_devicePixelRatio,
967
+ static_cast <Real>(znear)
968
+ ),
960
969
pos
961
970
);
962
971
}
0 commit comments