diff options
author | Erwin Coumans <erwincoumans@erwincoumans-macbookpro2.roam.corp.google.com> | 2017-09-20 10:07:18 -0700 |
---|---|---|
committer | Erwin Coumans <erwincoumans@erwincoumans-macbookpro2.roam.corp.google.com> | 2017-09-20 10:07:18 -0700 |
commit | fb057630935fca524da492f0d1fb5dee8a3283df (patch) | |
tree | 76542c022fa7a31bf20bf63ee1b4dd814c59c630 | |
parent | c47019e0af805561dda72699464907d22903edf3 (diff) | |
download | bullet3-fb057630935fca524da492f0d1fb5dee8a3283df.tar.gz |
support retina / scale factor between pixel size and screen coordinate size
-rw-r--r-- | data/multibody.bullet | bin | 14844 -> 14844 bytes | |||
-rw-r--r-- | examples/OpenGLWindow/GLFWOpenGLWindow.cpp | 28 | ||||
-rw-r--r-- | examples/OpenGLWindow/MacOpenGLWindow.cpp | 3 | ||||
-rw-r--r-- | examples/OpenGLWindow/MacOpenGLWindowObjC.m | 4 |
4 files changed, 24 insertions, 11 deletions
diff --git a/data/multibody.bullet b/data/multibody.bullet Binary files differindex b071e4eb7..bb56ec289 100644 --- a/data/multibody.bullet +++ b/data/multibody.bullet diff --git a/examples/OpenGLWindow/GLFWOpenGLWindow.cpp b/examples/OpenGLWindow/GLFWOpenGLWindow.cpp index b6e798eb6..dbc6434bf 100644 --- a/examples/OpenGLWindow/GLFWOpenGLWindow.cpp +++ b/examples/OpenGLWindow/GLFWOpenGLWindow.cpp @@ -29,6 +29,7 @@ struct GLFWOpenGLWindowInternalData b3RenderCallback m_renderCallback; int m_width; int m_height; + float m_retinaScaleFactor; GLFWwindow* m_glfwWindow; @@ -48,6 +49,7 @@ struct GLFWOpenGLWindowInternalData m_renderCallback(0), m_width(0), m_height(0), + m_retinaScaleFactor(1), m_glfwWindow(0) { } @@ -243,9 +245,8 @@ void GLFWOpenGLWindow::resizeInternal(int width,int height) { getResizeCallback()(width,height); } - m_data->m_width = width; - m_data->m_height = height; - glViewport (0,0,width,height); + glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height); + glViewport (0,0,m_data->m_width,m_data->m_height); } void GLFWOpenGLWindow::createDefaultWindow(int width, int height, const char* title) @@ -260,6 +261,7 @@ void GLFWOpenGLWindow::createDefaultWindow(int width, int height, const char* ti void GLFWOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) { + btAssert(m_data->m_glfwWindow==0); if (m_data->m_glfwWindow==0) { @@ -270,10 +272,12 @@ void GLFWOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) if (ci.m_openglVersion==2) { + printf("V2\n"); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); } else { + printf("V3\n"); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); @@ -282,14 +286,12 @@ void GLFWOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) m_data->m_glfwWindow = glfwCreateWindow(ci.m_width, ci.m_height, ci.m_title, NULL, NULL); - m_data->m_width = ci.m_width; - m_data->m_height = ci.m_height; + if (!m_data->m_glfwWindow) { glfwTerminate(); exit(EXIT_FAILURE); } - glfwSetKeyCallback(m_data->m_glfwWindow,GLFWKeyCallback); glfwSetMouseButtonCallback(m_data->m_glfwWindow,GLFWMouseButtonCallback); @@ -304,7 +306,11 @@ void GLFWOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) glfwMakeContextCurrent(m_data->m_glfwWindow); gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); glfwSwapInterval(0);//1); - + glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height); + int windowWidth, windowHeight; + glfwGetWindowSize(m_data->m_glfwWindow, &windowWidth, &windowHeight); + m_data->m_retinaScaleFactor = float(m_data->m_width)/float(windowWidth); + glViewport(0,0,m_data->m_width, m_data->m_height); } } @@ -416,6 +422,7 @@ b3MouseButtonCallback GLFWOpenGLWindow::getMouseButtonCallback() void GLFWOpenGLWindow::setResizeCallback(b3ResizeCallback resizeCallback) { m_data->m_resizeCallback = resizeCallback; + getResizeCallback()(m_data->m_width/getRetinaScale(),m_data->m_height/getRetinaScale()); } b3ResizeCallback GLFWOpenGLWindow::getResizeCallback() @@ -460,7 +467,7 @@ void GLFWOpenGLWindow::setWindowTitle(const char* title) float GLFWOpenGLWindow::getRetinaScale() const { - return 1.f; + return m_data->m_retinaScaleFactor; } void GLFWOpenGLWindow::setAllowRetina(bool allow) { @@ -472,7 +479,8 @@ int GLFWOpenGLWindow::getWidth() const { glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height); } - return m_data->m_width; + int width = m_data->m_width/m_data->m_retinaScaleFactor; + return width; } int GLFWOpenGLWindow::getHeight() const { @@ -480,7 +488,7 @@ int GLFWOpenGLWindow::getHeight() const { glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height); } - return m_data->m_height; + return m_data->m_height/m_data->m_retinaScaleFactor; } int GLFWOpenGLWindow::fileOpenDialog(char* fileName, int maxFileNameLength) diff --git a/examples/OpenGLWindow/MacOpenGLWindow.cpp b/examples/OpenGLWindow/MacOpenGLWindow.cpp index 7cb9a2718..5c13a80a2 100644 --- a/examples/OpenGLWindow/MacOpenGLWindow.cpp +++ b/examples/OpenGLWindow/MacOpenGLWindow.cpp @@ -1,3 +1,4 @@ +#ifndef B3_USE_GLFW #ifdef __APPLE__ #include "MacOpenGLWindow.h" @@ -190,6 +191,6 @@ void MacOpenGLWindow::setAllowRetina(bool allow) #endif //__APPLE__ - +#endif //B3_USE_GLFW diff --git a/examples/OpenGLWindow/MacOpenGLWindowObjC.m b/examples/OpenGLWindow/MacOpenGLWindowObjC.m index 3fc45fc43..29a2bd5f9 100644 --- a/examples/OpenGLWindow/MacOpenGLWindowObjC.m +++ b/examples/OpenGLWindow/MacOpenGLWindowObjC.m @@ -1,3 +1,5 @@ +#ifndef B3_USE_GLFW + #include "MacOpenGLWindowObjC.h" #define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED @@ -1231,3 +1233,5 @@ b3ResizeCallback Mac_getResizeCallback(struct MacOpenGLWindowInternalData* m_int { return [m_internalData->m_myview getResizeCallback]; } +#endif //B3_USE_GLFW + |