mirror of https://github.com/axmolengine/axmol.git
issue #202
This commit is contained in:
parent
6062cf1558
commit
64ac386384
|
@ -1,34 +1,39 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCRenderTexture.h"
|
#include "CCRenderTexture.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
#include "CCXUIImage.h"
|
#include "CCXUIImage.h"
|
||||||
#include <GLES/glext.h>
|
|
||||||
|
#ifdef IPHONE
|
||||||
namespace cocos2d {
|
#include <OpenGLES/ES1/glext.h>
|
||||||
|
#else
|
||||||
|
#include <GLES/glext.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace cocos2d {
|
||||||
|
|
||||||
// implementation CCRenderTexture
|
// implementation CCRenderTexture
|
||||||
CCSprite * CCRenderTexture::getSprite()
|
CCSprite * CCRenderTexture::getSprite()
|
||||||
|
@ -140,30 +145,30 @@ namespace cocos2d {
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
UIImage *myImage = this->getUIImageFromBuffer();
|
UIImage *myImage = this->getUIImageFromBuffer();
|
||||||
if (myImage)
|
if (myImage)
|
||||||
{
|
{
|
||||||
bRet = myImage->save(name, format);
|
bRet = myImage->save(name, format);
|
||||||
delete myImage;
|
delete myImage;
|
||||||
}
|
}
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get buffer as UIImage */
|
/* get buffer as UIImage */
|
||||||
UIImage * CCRenderTexture::getUIImageFromBuffer()
|
UIImage * CCRenderTexture::getUIImageFromBuffer()
|
||||||
{
|
{
|
||||||
int tx = (int)m_pTexture->getContentSize().width;
|
int tx = (int)m_pTexture->getContentSize().width;
|
||||||
int ty = (int)m_pTexture->getContentSize().height;
|
int ty = (int)m_pTexture->getContentSize().height;
|
||||||
|
|
||||||
void * pBuffer = new char[tx * ty * 4];
|
void * pBuffer = new char[tx * ty * 4];
|
||||||
|
|
||||||
this->begin();
|
this->begin();
|
||||||
glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, pBuffer);
|
glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, pBuffer);
|
||||||
this->end();
|
this->end();
|
||||||
|
|
||||||
UIImage *pRet = new UIImage();
|
UIImage *pRet = new UIImage();
|
||||||
pRet->initWithBuffer(tx, ty, (unsigned char*)pBuffer);
|
pRet->initWithBuffer(tx, ty, (unsigned char*)pBuffer);
|
||||||
delete[] pBuffer;
|
delete[] pBuffer;
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cocos2d
|
} // namespace cocos2d
|
||||||
|
|
Loading…
Reference in New Issue