Last active
August 29, 2015 14:05
-
-
Save t-takasaka/aa7a50528c36355129c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HelloWorldScene.h" | |
USING_NS_CC; | |
Scene* HelloWorld::createScene(){ | |
auto scene = Scene::create(); | |
auto layer = HelloWorld::create(); | |
scene->addChild(layer); | |
return scene; | |
} | |
bool HelloWorld::init(){ | |
if(!Layer::init()){ return false; } | |
m_visibleSize = Director::getInstance()->getVisibleSize(); | |
//元画像 | |
m_spriteSrc = Sprite::create("HelloWorld512.png"); | |
m_texSizeSrc = m_spriteSrc->getTexture()->getContentSizeInPixels(); | |
m_spriteSrc->setPosition(m_texSizeSrc / 2); | |
m_spriteSrc->retain(); | |
// this->addChild(m_spriteSrc); | |
//オフスクリーンレンダリング用のテクスチャ | |
m_texture1 = RenderTexture::create(m_texSizeSrc.width, m_texSizeSrc.height); | |
m_texture1->setPosition(m_visibleSize / 2); | |
m_texture1->retain(); | |
//こっちに画像データが移せたらよしとする | |
m_sprite1 = Sprite::create(); | |
m_sprite1->setVertexRect(Rect(0, 0, m_texSizeSrc.width, m_texSizeSrc.height)); | |
m_sprite1->setPosition(m_visibleSize / 2); | |
m_sprite1->retain(); | |
this->addChild(m_sprite1); | |
this->scheduleUpdate(); | |
return true; | |
} | |
void HelloWorld::update(float delta){ | |
//元画像をテクスチャバッファに描画 | |
m_texture1->beginWithClear(0, 0, 0, 1); | |
m_spriteSrc->visit(); | |
m_texture1->end(); | |
//テクスチャバッファからピクセルデータを取得 | |
Size texSize = m_spriteSrc->getContentSize(); | |
int wh = m_texSizeSrc.width * m_texSizeSrc.height; | |
Image *image = m_texture1->newImage(false); | |
Color4B *pixel = (Color4B*)image->getData(); | |
Color4B *start = pixel, *end = &pixel[wh]; | |
while(start != end){ | |
//ここでピクセルデータを加工する | |
++start; | |
} | |
//加工したピクセルデータをtexture2Dに移す | |
Texture2D *t2d = new Texture2D(); | |
t2d->initWithData(pixel, sizeof(pixel) * texSize.width * texSize.height, Texture2D::PixelFormat::RGBA8888, texSize.width, texSize.height, texSize); | |
t2d->initWithImage(image); | |
//texture2Dからスプライトに移す | |
m_sprite1->setTexture(t2d); | |
m_sprite1->setFlipY(true); | |
t2d->release(); | |
image->release(); | |
} | |
void HelloWorld::menuCloseCallback(Ref* pSender){ | |
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) | |
MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); | |
return; | |
#endif | |
Director::getInstance()->end(); | |
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) | |
exit(0); | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment