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
|
||||
|
||||
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 <GLES/glext.h>
|
||||
|
||||
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 <OpenGLES/ES1/glext.h>
|
||||
#else
|
||||
#include <GLES/glext.h>
|
||||
#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
|
||||
|
|
Loading…
Reference in New Issue