public RenderTextureIssue937() { /* * 1 2 * A: A1 A2 * * B: B1 B2 * * A1: premulti sprite * A2: premulti render * * B1: non-premulti sprite * B2: non-premulti render */ CCLayerColor background = CCLayerColor.layerWithColor(new ccColor4B(200, 200, 200, 255)); addChild(background); CCSprite spr_premulti = CCSprite.spriteWithFile("Images/fire.png"); spr_premulti.position = new CCPoint(16, 48); CCSprite spr_nonpremulti = CCSprite.spriteWithFile("Images/fire.png"); spr_nonpremulti.position = new CCPoint(16, 16); /* A2 & B2 setup */ CCRenderTexture rend = CCRenderTexture.renderTextureWithWidthAndHeight(32, 64); if (null == rend) { return; } // It's possible to modify the RenderTexture blending function by // [[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; rend.begin(); spr_premulti.visit(); spr_nonpremulti.visit(); rend.end(); CCSize s = CCDirector.sharedDirector().getWinSize(); /* A1: setup */ spr_premulti.position = new CCPoint(s.width / 2 - 16, s.height / 2 + 16); /* B1: setup */ spr_nonpremulti.position = new CCPoint(s.width / 2 - 16, s.height / 2 - 16); rend.position = new CCPoint(s.width / 2 + 16, s.height / 2); addChild(spr_nonpremulti); addChild(spr_premulti); addChild(rend); }
public RenderTextureTest() { //if (CCConfiguration.sharedConfiguration().getGlesVersion() <= GLES_VER_1_0) //{ // CCMessageBox("The Opengl ES version is lower than 1.1, and the test may not run correctly.", "Cocos2d-x Hint"); // return; //} CCSize s = CCDirector.sharedDirector().getWinSize(); // create a render texture, this is what we're going to draw into m_target = CCRenderTexture.renderTextureWithWidthAndHeight((int)s.width, (int)s.height); if (null == m_target) { return; } m_target.position = new CCPoint(s.width / 2, s.height / 2); // note that the render texture is a cocosnode, and contains a sprite of it's texture for convience, // so we can just parent it to the scene like any other cocos node addChild(m_target, 1); // create a brush image to draw into the texture with m_brush = CCSprite.spriteWithFile("Images/stars.png"); //m_brush.retain(); ccBlendFunc bf = new ccBlendFunc { src = 1, dst = 0x0303 }; m_brush.BlendFunc = bf; m_brush.Opacity = 20; isTouchEnabled = true; }