void CCRenderTexture::end(bool bIsTOCacheTexture) { // not save data, because it is slow bIsTOCacheTexture = false; ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO); // Restore the original matrix and viewport glPopMatrix(); CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels(); // glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height); CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height); #if CC_ENABLE_CACHE_TEXTTURE_DATA if (bIsTOCacheTexture) { CC_SAFE_DELETE(m_pUITextureImage); // to get the rendered texture data const CCSize& s = m_pTexture->getContentSizeInPixels(); int tx = (int)s.width; int ty = (int)s.height; m_pUITextureImage = new CCImage; if (true == getUIImageFromBuffer(m_pUITextureImage, 0, 0, tx, ty)) { VolatileTexture::addDataTexture(m_pTexture, m_pUITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s); } else { CCLOG("Cache rendertexture failed!"); } } #endif }
bool CCRenderTexture::saveBuffer(const char *fileName, int format) { bool bRet = false; CCAssert(format == kCCImageFormatJPG || format == kCCImageFormatPNG, "the image can only be saved as JPG or PNG format"); CCImage *pImage = new CCImage(); if (pImage != NULL && getUIImageFromBuffer(pImage)) { std::string fullpath = CCFileUtils::getWriteablePath() + fileName; if (kCCImageFormatPNG == format) { fullpath += ".png"; } else { fullpath += ".jpg"; } bRet = pImage->saveToFile(fullpath.c_str()); } CC_SAFE_DELETE(pImage); return bRet; }
bool CCRenderTexture::saveBuffer(const char *szFilePath, int x, int y, int nWidth, int nHeight) { bool bRet = false; CCImage *pImage = new CCImage(); if (pImage != NULL && getUIImageFromBuffer(pImage, x, y, nWidth, nHeight)) { bRet = pImage->saveToFile(szFilePath); } CC_SAFE_DELETE(pImage); return bRet; }
bool CCRenderTexture::saveBuffer(int format, const char *fileName, int x, int y, int nWidth, int nHeight) { bool bRet = false; CCAssert(format == kCCImageFormatJPG || format == kCCImageFormatPNG, "the image can only be saved as JPG or PNG format"); CCImage *pImage = new CCImage(); if (pImage != NULL && getUIImageFromBuffer(pImage, x, y, nWidth, nHeight)) { std::string fullpath = CCFileUtils::getWriteablePath() + fileName; bRet = pImage->saveToFile(fullpath.c_str()); } CC_SAFE_DELETE(pImage); return bRet; }