diff --git a/cocos2dx/platform/linux/CCEGLView.cpp b/cocos2dx/platform/linux/CCEGLView.cpp index 36d556b8de..a0d31caa6a 100644 --- a/cocos2dx/platform/linux/CCEGLView.cpp +++ b/cocos2dx/platform/linux/CCEGLView.cpp @@ -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,21 +268,26 @@ 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); CCLOG("OpenGL version = %s", glVersion); @@ -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() diff --git a/cocos2dx/platform/linux/CCEGLView.h b/cocos2dx/platform/linux/CCEGLView.h index f2ed8f4a21..1e8c8e9c6c 100644 --- a/cocos2dx/platform/linux/CCEGLView.h +++ b/cocos2dx/platform/linux/CCEGLView.h @@ -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: diff --git a/cocos2dx/platform/mac/CCEGLView.h b/cocos2dx/platform/mac/CCEGLView.h index a72ef8cf93..222bba5348 100644 --- a/cocos2dx/platform/mac/CCEGLView.h +++ b/cocos2dx/platform/mac/CCEGLView.h @@ -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: diff --git a/cocos2dx/platform/mac/CCEGLView.mm b/cocos2dx/platform/mac/CCEGLView.mm index 7e14cfe213..eddf3e80d1 100644 --- a/cocos2dx/platform/mac/CCEGLView.mm +++ b/cocos2dx/platform/mac/CCEGLView.mm @@ -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() diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 46e3e1b7ba..a58bd59941 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -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() diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index 71d7335dfa..5c5a2b4407 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -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: diff --git a/make-all-linux-project.sh b/make-all-linux-project.sh index 4889355380..b0d3ef0881 100755 --- a/make-all-linux-project.sh +++ b/make-all-linux-project.sh @@ -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 diff --git a/tools/travis-scripts/install_glfw.sh b/tools/travis-scripts/install_glfw.sh index e7236593a5..caeabdc998 100755 --- a/tools/travis-scripts/install_glfw.sh +++ b/tools/travis-scripts/install_glfw.sh @@ -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 .. }