Merge pull request #16160 from ricardoquesada/issue_16139

fix: display FPS again on GLFW platforms
This commit is contained in:
Ricardo Quesada 2016-07-19 19:19:31 -07:00 committed by GitHub
commit cc947737dd
2 changed files with 14 additions and 5 deletions

View File

@ -606,6 +606,12 @@ void Director::setProjection(Projection projection)
{
Size size = _winSizeInPoints;
if (size.width == 0 || size.height == 0)
{
CCLOGERROR("cocos2d: warning, Director::setProjection() failed because size is 0");
return;
}
setViewport();
switch (projection)

View File

@ -361,10 +361,10 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
glfwWindowHint(GLFW_DEPTH_BITS,_glContextAttrs.depthBits);
glfwWindowHint(GLFW_STENCIL_BITS,_glContextAttrs.stencilBits);
int needWidth = rect.size.width * _frameZoomFactor;
int neeHeight = rect.size.height * _frameZoomFactor;
int neededWidth = rect.size.width * _frameZoomFactor;
int neededHeight = rect.size.height * _frameZoomFactor;
_mainWindow = glfwCreateWindow(needWidth, neeHeight, _viewName.c_str(), _monitor, nullptr);
_mainWindow = glfwCreateWindow(neededWidth, neededHeight, _viewName.c_str(), _monitor, nullptr);
if (_mainWindow == nullptr)
{
@ -391,11 +391,11 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
*/
int realW = 0, realH = 0;
glfwGetWindowSize(_mainWindow, &realW, &realH);
if (realW != needWidth)
if (realW != neededWidth)
{
rect.size.width = realW / _frameZoomFactor;
}
if (realH != neeHeight)
if (realH != neededHeight)
{
rect.size.height = realH / _frameZoomFactor;
}
@ -432,6 +432,9 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
// Enable point size by default.
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
// GLFW v3.2 no longer emits "onGLFWWindowSizeFunCallback" at creation time. Force default viewport:
setViewPortInPoints(0, 0, neededWidth, neededHeight);
return true;
}