From 64ac386384ba5007bddffa1bcebe9156814a2c48 Mon Sep 17 00:00:00 2001 From: Ming Date: Fri, 12 Nov 2010 09:29:14 +0000 Subject: [PATCH] issue #202 --- cocos2dx/misc_nodes/CCRenderTexture.cpp | 109 +++++++++++++----------- 1 file changed, 57 insertions(+), 52 deletions(-) diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp index 5dc078a223..cd28b9f581 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.cpp +++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp @@ -1,34 +1,39 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "CCRenderTexture.h" -#include "CCDirector.h" -#include "platform/platform.h" -#include "CCXUIImage.h" -#include - -namespace cocos2d { +/**************************************************************************** +Copyright (c) 2010 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#include "CCRenderTexture.h" +#include "CCDirector.h" +#include "platform/platform.h" +#include "CCXUIImage.h" + +#ifdef IPHONE + #include +#else + #include +#endif + +namespace cocos2d { // implementation CCRenderTexture CCSprite * CCRenderTexture::getSprite() @@ -140,30 +145,30 @@ namespace cocos2d { { bool bRet = false; UIImage *myImage = this->getUIImageFromBuffer(); - if (myImage) - { - bRet = myImage->save(name, format); - delete myImage; - } - return bRet; + if (myImage) + { + bRet = myImage->save(name, format); + delete myImage; + } + return bRet; } /* get buffer as UIImage */ UIImage * CCRenderTexture::getUIImageFromBuffer() { - int tx = (int)m_pTexture->getContentSize().width; - int ty = (int)m_pTexture->getContentSize().height; - - void * pBuffer = new char[tx * ty * 4]; - - this->begin(); - glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, pBuffer); - this->end(); - - UIImage *pRet = new UIImage(); - pRet->initWithBuffer(tx, ty, (unsigned char*)pBuffer); - delete[] pBuffer; - return pRet; + int tx = (int)m_pTexture->getContentSize().width; + int ty = (int)m_pTexture->getContentSize().height; + + void * pBuffer = new char[tx * ty * 4]; + + this->begin(); + glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, pBuffer); + this->end(); + + UIImage *pRet = new UIImage(); + pRet->initWithBuffer(tx, ty, (unsigned char*)pBuffer); + delete[] pBuffer; + return pRet; } - -} // namespace cocos2d + +} // namespace cocos2d