mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3606 from dabingnn/issue_2808_glfw_bug_enhancement
Issue 2808 glfw bug enhancement
This commit is contained in:
commit
e4f8929898
|
@ -161,6 +161,7 @@ public:
|
|||
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
||||
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
||||
static void OnGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
|
||||
};
|
||||
|
||||
bool EGLViewEventHandler::s_captured = false;
|
||||
|
@ -232,6 +233,13 @@ void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int ch
|
|||
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWWindowPosCallback(GLFWwindow *windows, int x, int y)
|
||||
{
|
||||
if(Director::getInstance())
|
||||
{
|
||||
Director::getInstance()->setViewport();
|
||||
}
|
||||
}
|
||||
//end EGLViewEventHandler
|
||||
|
||||
|
||||
|
@ -260,20 +268,25 @@ EGLView::~EGLView()
|
|||
s_pEglView = nullptr;
|
||||
}
|
||||
|
||||
bool EGLView::init(const char* viewName, float width, float height)
|
||||
bool EGLView::init(const char* viewName, float width, float height, float frameZoomFactor)
|
||||
{
|
||||
if(nullptr != _mainWindow) return true;
|
||||
|
||||
setViewName(viewName);
|
||||
setFrameSize(width, height);
|
||||
setFrameZoomFactor(frameZoomFactor);
|
||||
|
||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
||||
_mainWindow = glfwCreateWindow(_screenSize.width, _screenSize.height, _viewName, nullptr, nullptr);
|
||||
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr);
|
||||
glfwMakeContextCurrent(_mainWindow);
|
||||
|
||||
glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
|
||||
|
||||
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
||||
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
||||
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
||||
glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback);
|
||||
glfwSetWindowPosCallback(_mainWindow, EGLViewEventHandler::OnGLFWWindowPosCallback);
|
||||
|
||||
// check OpenGL version at first
|
||||
const GLubyte* glVersion = glGetString(GL_VERSION);
|
||||
|
@ -379,18 +392,22 @@ void EGLView::setFrameSize(float width, float height)
|
|||
|
||||
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
glViewport((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glViewport((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
}
|
||||
|
||||
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
glScissor((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glScissor((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
}
|
||||
|
||||
EGLView* EGLView::getInstance()
|
||||
|
|
|
@ -38,15 +38,13 @@ public:
|
|||
virtual void swapBuffers();
|
||||
virtual void setFrameSize(float width, float height);
|
||||
virtual void setIMEKeyboardState(bool bOpen);
|
||||
|
||||
bool init(const char* viewName, float width, float height);
|
||||
/*
|
||||
*frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
bool init(const char* viewName, float width, float height, float frameZoomFactor = 1.0f);
|
||||
public:
|
||||
|
||||
//void resize(int width, int height);
|
||||
/*
|
||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
void setFrameZoomFactor(float fZoomFactor);
|
||||
float getFrameZoomFactor();
|
||||
//void centerWindow();
|
||||
|
||||
|
@ -63,11 +61,15 @@ public:
|
|||
/** @deprecated Use getInstance() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
||||
protected:
|
||||
|
||||
/*
|
||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
void setFrameZoomFactor(float fZoomFactor);
|
||||
private:
|
||||
bool _captured;
|
||||
bool _supportTouch;
|
||||
|
||||
int _frameBufferSize[2];
|
||||
float _frameZoomFactor;
|
||||
static EGLView* s_pEglView;
|
||||
public:
|
||||
|
|
|
@ -50,15 +50,14 @@ public:
|
|||
virtual void swapBuffers();
|
||||
virtual void setFrameSize(float width, float height);
|
||||
virtual void setIMEKeyboardState(bool bOpen);
|
||||
|
||||
bool init(const char* viewName, float width, float height);
|
||||
/*
|
||||
*frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
bool init(const char* viewName, float width, float height, float frameZoomFactor = 1.0f);
|
||||
public:
|
||||
|
||||
//void resize(int width, int height);
|
||||
/*
|
||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
void setFrameZoomFactor(float fZoomFactor);
|
||||
|
||||
float getFrameZoomFactor();
|
||||
//void centerWindow();
|
||||
|
||||
|
@ -75,11 +74,15 @@ public:
|
|||
/** @deprecated Use getInstance() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
||||
protected:
|
||||
|
||||
/*
|
||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
void setFrameZoomFactor(float fZoomFactor);
|
||||
private:
|
||||
bool _captured;
|
||||
bool _supportTouch;
|
||||
|
||||
int _frameBufferSize[2];
|
||||
float _frameZoomFactor;
|
||||
static EGLView* s_pEglView;
|
||||
public:
|
||||
|
|
|
@ -177,6 +177,7 @@ public:
|
|||
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
||||
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
||||
static void OnGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
|
||||
};
|
||||
|
||||
bool EGLViewEventHandler::s_captured = false;
|
||||
|
@ -248,6 +249,14 @@ void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int ch
|
|||
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWWindowPosCallback(GLFWwindow *windows, int x, int y)
|
||||
{
|
||||
if(Director::getInstance())
|
||||
{
|
||||
Director::getInstance()->setViewport();
|
||||
}
|
||||
}
|
||||
|
||||
//end EGLViewEventHandler
|
||||
|
||||
|
||||
|
@ -277,20 +286,25 @@ EGLView::~EGLView()
|
|||
s_pEglView = nullptr;
|
||||
}
|
||||
|
||||
bool EGLView::init(const char *viewName, float width, float height)
|
||||
bool EGLView::init(const char *viewName, float width, float height, float frameZoomFactor)
|
||||
{
|
||||
if(nullptr != _mainWindow) return true;
|
||||
|
||||
setViewName(viewName);
|
||||
setFrameSize(width, height);
|
||||
setFrameZoomFactor(frameZoomFactor);
|
||||
|
||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
||||
_mainWindow = glfwCreateWindow(_screenSize.width, _screenSize.height, _viewName, nullptr, nullptr);
|
||||
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr);
|
||||
glfwMakeContextCurrent(_mainWindow);
|
||||
|
||||
glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
|
||||
|
||||
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
||||
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
||||
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
||||
glfwSetKeyCallback(_mainWindow, EGLViewEventHandler::OnGLFWKeyCallback);
|
||||
glfwSetWindowPosCallback(_mainWindow, EGLViewEventHandler::OnGLFWWindowPosCallback);
|
||||
|
||||
// check OpenGL version at first
|
||||
const GLubyte* glVersion = glGetString(GL_VERSION);
|
||||
|
@ -396,18 +410,22 @@ void EGLView::setFrameSize(float width, float height)
|
|||
|
||||
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
glViewport((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glViewport((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
}
|
||||
|
||||
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
glScissor((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glScissor((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
}
|
||||
|
||||
EGLView* EGLView::getInstance()
|
||||
|
|
|
@ -271,6 +271,7 @@ public:
|
|||
static void OnGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
|
||||
static void OnGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
static void OnGLFWCharCallback(GLFWwindow* window, unsigned int character);
|
||||
static void OnGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
|
||||
};
|
||||
|
||||
bool EGLViewEventHandler::s_captured = false;
|
||||
|
@ -320,8 +321,8 @@ void EGLViewEventHandler::OnGLFWMouseMoveCallBack(GLFWwindow* window, double x,
|
|||
EGLView* eglView = EGLView::getInstance();
|
||||
if(nullptr == eglView) return;
|
||||
|
||||
s_mouseX *= eglView->getFrameZoomFactor();
|
||||
s_mouseY *= eglView->getFrameZoomFactor();
|
||||
s_mouseX /= eglView->getFrameZoomFactor();
|
||||
s_mouseY /= eglView->getFrameZoomFactor();
|
||||
|
||||
if(s_captured)
|
||||
{
|
||||
|
@ -346,6 +347,14 @@ void EGLViewEventHandler::OnGLFWCharCallback(GLFWwindow *window, unsigned int ch
|
|||
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*) &character, 1);
|
||||
}
|
||||
|
||||
void EGLViewEventHandler::OnGLFWWindowPosCallback(GLFWwindow *windows, int x, int y)
|
||||
{
|
||||
if(Director::getInstance())
|
||||
{
|
||||
Director::getInstance()->setViewport();
|
||||
}
|
||||
}
|
||||
|
||||
//end EGLViewEventHandler
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -374,16 +383,19 @@ EGLView::~EGLView()
|
|||
s_pEglView = nullptr;
|
||||
}
|
||||
|
||||
bool EGLView::init(const char* viewName, float width, float height)
|
||||
bool EGLView::init(const char* viewName, float width, float height, float frameZoomFactor)
|
||||
{
|
||||
if(nullptr != _mainWindow) return true;
|
||||
|
||||
setViewName(viewName);
|
||||
setFrameSize(width, height);
|
||||
setFrameZoomFactor(frameZoomFactor);
|
||||
|
||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
|
||||
_mainWindow = glfwCreateWindow(_screenSize.width, _screenSize.height, _viewName, nullptr, nullptr);
|
||||
_mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr);
|
||||
glfwMakeContextCurrent(_mainWindow);
|
||||
|
||||
glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]);
|
||||
glfwSetMouseButtonCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseCallBack);
|
||||
glfwSetCursorPosCallback(_mainWindow,EGLViewEventHandler::OnGLFWMouseMoveCallBack);
|
||||
glfwSetCharCallback(_mainWindow, EGLViewEventHandler::OnGLFWCharCallback);
|
||||
|
@ -499,18 +511,22 @@ void EGLView::setFrameSize(float width, float height)
|
|||
|
||||
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
glViewport((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glViewport((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
}
|
||||
|
||||
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
||||
{
|
||||
glScissor((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
||||
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
||||
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
||||
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
||||
float frameZoomFactorX = _frameBufferSize[0]/_screenSize.width;
|
||||
float frameZoomFactorY = _frameBufferSize[1]/_screenSize.height;
|
||||
glScissor((GLint)(x * _scaleX * frameZoomFactorX + _viewPortRect.origin.x * frameZoomFactorX),
|
||||
(GLint)(y * _scaleY * frameZoomFactorY + _viewPortRect.origin.y * frameZoomFactorY),
|
||||
(GLsizei)(w * _scaleX * frameZoomFactorX),
|
||||
(GLsizei)(h * _scaleY * frameZoomFactorY));
|
||||
}
|
||||
|
||||
EGLView* EGLView::getInstance()
|
||||
|
|
|
@ -55,15 +55,13 @@ public:
|
|||
virtual void swapBuffers();
|
||||
virtual void setFrameSize(float width, float height);
|
||||
virtual void setIMEKeyboardState(bool bOpen);
|
||||
|
||||
bool init(const char* viewName, float width, float height);
|
||||
/*
|
||||
*frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
bool init(const char* viewName, float width, float height, float frameZoomFactor = 1.0f);
|
||||
public:
|
||||
|
||||
//void resize(int width, int height);
|
||||
/*
|
||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
void setFrameZoomFactor(float fZoomFactor);
|
||||
float getFrameZoomFactor();
|
||||
//void centerWindow();
|
||||
|
||||
|
@ -82,12 +80,16 @@ public:
|
|||
/** @deprecated Use getInstance() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE static EGLView* sharedOpenGLView();
|
||||
protected:
|
||||
|
||||
/*
|
||||
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
||||
*/
|
||||
void setFrameZoomFactor(float fZoomFactor);
|
||||
private:
|
||||
bool _captured;
|
||||
LPFN_ACCELEROMETER_KEYHOOK _lpfnAccelerometerKeyHook;
|
||||
bool _supportTouch;
|
||||
|
||||
int _frameBufferSize[2];
|
||||
float _frameZoomFactor;
|
||||
static EGLView* s_pEglView;
|
||||
public:
|
||||
|
|
|
@ -15,6 +15,7 @@ cd $(dirname ${BASH_SOURCE[0]})
|
|||
|
||||
if $COCOS2DX_USEAPT; then
|
||||
./install-deps-linux.sh
|
||||
tools/travis-scripts/install_glfw.sh
|
||||
fi
|
||||
|
||||
export MAKEFLAGS=-j10
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
GLFW_VERSION="3.0.1"
|
||||
GLFW_VERSION="3.0.2"
|
||||
GLFW_SOURCE="https://codeload.github.com/glfw/glfw/tar.gz/${GLFW_VERSION}"
|
||||
GLFW_ZIP="glfw${GLFW_VERSION}.tar.gz"
|
||||
GLFW_INSTALL="glfw_install"
|
||||
|
@ -12,6 +12,7 @@ install_glfw_dep()
|
|||
sudo apt-get install xorg-dev
|
||||
sudo apt-get install libglu1-mesa-dev
|
||||
sudo apt-get install cmake
|
||||
sudo apt-get install curl
|
||||
}
|
||||
|
||||
clean_tmp_file()
|
||||
|
@ -26,6 +27,7 @@ make_and_install()
|
|||
cmake "../${GLFW_SRCDIR}" -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON
|
||||
make
|
||||
sudo make install
|
||||
sudo ldconfig
|
||||
cd ..
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue