support retina / scale factor between pixel size and screen coordinate size
This commit is contained in:
Binary file not shown.
@@ -29,6 +29,7 @@ struct GLFWOpenGLWindowInternalData
|
|||||||
b3RenderCallback m_renderCallback;
|
b3RenderCallback m_renderCallback;
|
||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
|
float m_retinaScaleFactor;
|
||||||
|
|
||||||
GLFWwindow* m_glfwWindow;
|
GLFWwindow* m_glfwWindow;
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ struct GLFWOpenGLWindowInternalData
|
|||||||
m_renderCallback(0),
|
m_renderCallback(0),
|
||||||
m_width(0),
|
m_width(0),
|
||||||
m_height(0),
|
m_height(0),
|
||||||
|
m_retinaScaleFactor(1),
|
||||||
m_glfwWindow(0)
|
m_glfwWindow(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -243,9 +245,8 @@ void GLFWOpenGLWindow::resizeInternal(int width,int height)
|
|||||||
{
|
{
|
||||||
getResizeCallback()(width,height);
|
getResizeCallback()(width,height);
|
||||||
}
|
}
|
||||||
m_data->m_width = width;
|
glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height);
|
||||||
m_data->m_height = height;
|
glViewport (0,0,m_data->m_width,m_data->m_height);
|
||||||
glViewport (0,0,width,height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLFWOpenGLWindow::createDefaultWindow(int width, int height, const char* title)
|
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)
|
void GLFWOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
||||||
{
|
{
|
||||||
|
|
||||||
btAssert(m_data->m_glfwWindow==0);
|
btAssert(m_data->m_glfwWindow==0);
|
||||||
if (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)
|
if (ci.m_openglVersion==2)
|
||||||
{
|
{
|
||||||
|
printf("V2\n");
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
printf("V3\n");
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
@@ -282,15 +286,13 @@ 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_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)
|
if (!m_data->m_glfwWindow)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glfwSetKeyCallback(m_data->m_glfwWindow,GLFWKeyCallback);
|
glfwSetKeyCallback(m_data->m_glfwWindow,GLFWKeyCallback);
|
||||||
glfwSetMouseButtonCallback(m_data->m_glfwWindow,GLFWMouseButtonCallback);
|
glfwSetMouseButtonCallback(m_data->m_glfwWindow,GLFWMouseButtonCallback);
|
||||||
|
|
||||||
@@ -304,7 +306,11 @@ void GLFWOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
|||||||
glfwMakeContextCurrent(m_data->m_glfwWindow);
|
glfwMakeContextCurrent(m_data->m_glfwWindow);
|
||||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||||
glfwSwapInterval(0);//1);
|
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)
|
void GLFWOpenGLWindow::setResizeCallback(b3ResizeCallback resizeCallback)
|
||||||
{
|
{
|
||||||
m_data->m_resizeCallback = resizeCallback;
|
m_data->m_resizeCallback = resizeCallback;
|
||||||
|
getResizeCallback()(m_data->m_width/getRetinaScale(),m_data->m_height/getRetinaScale());
|
||||||
}
|
}
|
||||||
|
|
||||||
b3ResizeCallback GLFWOpenGLWindow::getResizeCallback()
|
b3ResizeCallback GLFWOpenGLWindow::getResizeCallback()
|
||||||
@@ -460,7 +467,7 @@ void GLFWOpenGLWindow::setWindowTitle(const char* title)
|
|||||||
|
|
||||||
float GLFWOpenGLWindow::getRetinaScale() const
|
float GLFWOpenGLWindow::getRetinaScale() const
|
||||||
{
|
{
|
||||||
return 1.f;
|
return m_data->m_retinaScaleFactor;
|
||||||
}
|
}
|
||||||
void GLFWOpenGLWindow::setAllowRetina(bool allow)
|
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);
|
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
|
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);
|
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)
|
int GLFWOpenGLWindow::fileOpenDialog(char* fileName, int maxFileNameLength)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#ifndef B3_USE_GLFW
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
||||||
#include "MacOpenGLWindow.h"
|
#include "MacOpenGLWindow.h"
|
||||||
@@ -190,6 +191,6 @@ void MacOpenGLWindow::setAllowRetina(bool allow)
|
|||||||
|
|
||||||
|
|
||||||
#endif //__APPLE__
|
#endif //__APPLE__
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#ifndef B3_USE_GLFW
|
||||||
|
|
||||||
#include "MacOpenGLWindowObjC.h"
|
#include "MacOpenGLWindowObjC.h"
|
||||||
|
|
||||||
#define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
|
#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];
|
return [m_internalData->m_myview getResizeCallback];
|
||||||
}
|
}
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user