// RenderTextureTest RenderTextureTargetNode::RenderTextureTargetNode() { /* * 1 2 * A: A1 A2 * * B: B1 B2 * * A1: premulti sprite * A2: premulti render * * B1: non-premulti sprite * B2: non-premulti render */ auto background = LayerColor::create(Color4B(40,40,40,255)); addChild(background); // sprite 1 sprite1 = Sprite::create("Images/fire.png"); // sprite 2 sprite2 = Sprite::create("Images/fire_rgba8888.pvr"); auto s = Director::getInstance()->getWinSize(); /* Create the render texture */ auto renderTexture = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444); this->renderTexture = renderTexture; renderTexture->setPosition(Point(s.width/2, s.height/2)); // [renderTexture setPosition:Point(s.width, s.height)]; // renderTexture.scale = 2; /* add the sprites to the render texture */ renderTexture->addChild(sprite1); renderTexture->addChild(sprite2); renderTexture->setClearColor(Color4F(0, 0, 0, 0)); renderTexture->setClearFlags(GL_COLOR_BUFFER_BIT); /* add the render texture to the scene */ addChild(renderTexture); renderTexture->setAutoDraw(true); scheduleUpdate(); // Toggle clear on / off auto item = MenuItemFont::create("Clear On/Off", CC_CALLBACK_1(RenderTextureTargetNode::touched, this)); auto menu = Menu::create(item, NULL); addChild(menu); menu->setPosition(Point(s.width/2, s.height/2)); }
void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) { setClearColor(Color4F(r, g, b, a)); setClearDepth(depthValue); setClearStencil(stencilValue); setClearFlags(flags); this->begin(); //clear screen _beginWithClearCommand.init(_globalZOrder); _beginWithClearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this); Director::getInstance()->getRenderer()->addCommand(&_beginWithClearCommand); }