diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index b2d30f348a..f8b3bd3cdc 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -194,11 +194,12 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat do { _fullRect = _rtTextureRect = Rect(0,0,w,h); - Size size = Director::getInstance()->getWinSizeInPixels(); - _fullviewPort = Rect(0,0,size.width,size.height); + //Size size = Director::getInstance()->getWinSizeInPixels(); + //_fullviewPort = Rect(0,0,size.width,size.height); w = (int)(w * CC_CONTENT_SCALE_FACTOR()); h = (int)(h * CC_CONTENT_SCALE_FACTOR()); - + _fullviewPort = Rect(0,0,w,h); + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); // textures must be power of two squared @@ -522,7 +523,6 @@ void RenderTexture::onBegin() { // Director *director = Director::getInstance(); - Size size = director->getWinSizeInPixels(); _oldProjMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _projectionMatrix); @@ -541,14 +541,17 @@ void RenderTexture::onBegin() #endif const Size& texSize = _texture->getContentSizeInPixels(); - + // Calculate the adjustment ratios based on the old and new projections + Size size = director->getWinSizeInPixels(); float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; + Matrix orthoMatrix; Matrix::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &orthoMatrix); - director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, orthoMatrix); + director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix); } + //calculate viewport { Rect viewport; @@ -696,12 +699,13 @@ void RenderTexture::begin() // Calculate the adjustment ratios based on the old and new projections Size size = director->getWinSizeInPixels(); + float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; Matrix orthoMatrix; Matrix::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &orthoMatrix); - director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, orthoMatrix); + director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix); } _groupCommand.init(_globalZOrder); diff --git a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp index 898f3f06a4..99b991281d 100644 --- a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -408,8 +408,7 @@ void RenderTextureZbuffer::renderScreenShot() { return; } - texture->setAnchorPoint(Vector2(0, 0)); - texture->setKeepMatrix(true); + texture->begin(); this->visit();