public RenderTextureSave() { CCSize s = CCDirector.SharedDirector.WinSize; // create a render texture, this is what we are going to draw into m_pTarget = CCRenderTexture.Create((int) s.Width, (int) s.Height, SurfaceFormat.Color, DepthFormat.None, RenderTargetUsage.PreserveContents); m_pTarget.Position = new CCPoint(s.Width / 2, s.Height / 2); // It's possible to modify the RenderTexture blending function by //CCBlendFunc tbf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); //m_pTarget.Sprite.BlendFunc = tbf; // note that the render texture is a CCNode, and contains a sprite of its texture for convience, // so we can just parent it to the scene like any other CCNode AddChild(m_pTarget, -1); // create a brush image to draw into the texture with m_pBrush = new CCSprite("Images/fire"); // It's possible to modify the Brushes blending function by CCBlendFunc bbf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); m_pBrush.BlendFunc = bbf; m_pBrush.Color = new CCColor3B (Color.Red); m_pBrush.Opacity = 20; TouchEnabled = true; // Save Image menu CCMenuItemFont.FontSize = 16; CCMenuItem item1 = CCMenuItemFont.Create("Save Image", saveImage); CCMenuItem item2 = CCMenuItemFont.Create("Clear", clearImage); var menu = new CCMenu(item1, item2); AddChild(menu); menu.AlignItemsVertically(); menu.Position = new CCPoint(s.Width - 80, s.Height - 30); }
public RenderTextureSave() { CCSize s = CCDirector.sharedDirector().getWinSize(); // create a render texture, this is what we are going to draw into m_pTarget = CCRenderTexture.renderTextureWithWidthAndHeight((int)s.width, (int)s.height); //m_pTarget->retain(); m_pTarget.position = new CCPoint(s.width / 2, s.height / 2); // note that the render texture is a CCNode, and contains a sprite of its texture for convience, // so we can just parent it to the scene like any other CCNode this.addChild(m_pTarget, -1); // create a brush image to draw into the texture with m_pBrush = CCSprite.spriteWithFile("Images/fire.png"); //m_pBrush->retain(); m_pBrush.Opacity = 20; //this->setIsTouchEnabled(true); isTouchEnabled = true; // Save Image menu CCMenuItemFont.FontSize = 16; CCMenuItem item1 = CCMenuItemFont.itemFromString("Save Image", this, saveImage); CCMenuItem item2 = CCMenuItemFont.itemFromString("Clear", this, clearImage); CCMenu menu = CCMenu.menuWithItems(item1, item2); this.addChild(menu); menu.alignItemsVertically(); menu.position = new CCPoint(s.width - 80, s.height - 30); }
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; }
public override void onEnter() { base.onEnter(); CCSize winSize = CCDirector.sharedDirector().getWinSize(); CCRenderTexture cCPoint = CCRenderTexture.renderTextureWithWidthAndHeight((int)winSize.width, (int)winSize.height); if (cCPoint == null) { return; } cCPoint.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); cCPoint.position = new CCPoint(winSize.width / 2f, winSize.height / 2f); cCPoint.anchorPoint = new CCPoint(0.5f, 0.5f); cCPoint.clear(0f, 0f, 0f, 1f); cCPoint.begin(); this.m_pOutScene.visit(); cCPoint.end(); base.hideOutShowIn(); CCProgressTimer cCProgressTimer = CCProgressTimer.progressWithTexture(cCPoint.Sprite.Texture); cCProgressTimer.Type = this.radialType(); cCProgressTimer.Percentage = 100f; cCProgressTimer.position = new CCPoint(winSize.width / 2f, winSize.height / 2f); cCProgressTimer.anchorPoint = new CCPoint(0.5f, 0.5f); CCFiniteTimeAction[] cCFiniteTimeActionArray = new CCFiniteTimeAction[] { CCProgressFromTo.actionWithDuration(this.m_fDuration, 100f, 0f), CCCallFunc.actionWithTarget(this, new SEL_CallFunc(this.finish)) }; cCProgressTimer.runAction(CCSequence.actions(cCFiniteTimeActionArray)); this.addChild(cCProgressTimer, 2, 2147483647); }
public static CCRenderTexture renderTextureWithWidthAndHeight(int w, int h) { CCRenderTexture cCRenderTexture = new CCRenderTexture(); if (cCRenderTexture.initWithWidthAndHeight(w, h, CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888)) { return(cCRenderTexture); } return(null); }
public RenderTextureTestDepthStencil() { CCSize s = CCDirector.SharedDirector.WinSize; CCSprite sprite = new CCSprite("Images/fire"); sprite.Position = new CCPoint(s.Width * 0.25f, 0); sprite.Scale = 10; CCRenderTexture rend = new CCRenderTexture((int)s.Width, (int)s.Height, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, RenderTargetUsage.DiscardContents); rend.BeginWithClear(0, 0, 0, 0, 0); var save = DrawManager.DepthStencilState; DrawManager.DepthStencilState = new DepthStencilState() { ReferenceStencil = 1, DepthBufferEnable = false, StencilEnable = true, StencilFunction = CompareFunction.Always, StencilPass = StencilOperation.Replace, TwoSidedStencilMode = true, CounterClockwiseStencilFunction = CompareFunction.Always, CounterClockwiseStencilPass = StencilOperation.Replace, }; sprite.Visit(); DrawManager.DepthStencilState = new DepthStencilState() { DepthBufferEnable = false, StencilEnable = true, StencilFunction = CompareFunction.NotEqual, StencilPass = StencilOperation.Keep, ReferenceStencil = 1 }; // GL_SRC_ALPHA DrawManager.BlendFunc(new CCBlendFunc(OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA)); //! move sprite half width and height, and draw only where not marked sprite.Position = sprite.Position + new CCPoint(sprite.ContentSize.Width * sprite.Scale, sprite.ContentSize.Height * sprite.Scale) * 0.5f; sprite.Visit(); DrawManager.DepthStencilState = save; rend.End(); rend.Position = new CCPoint(s.Width * 0.5f, s.Height * 0.5f); AddChild(rend); }
/// <summary> /// creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> public static CCRenderTexture renderTextureWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { CCRenderTexture pRet = new CCRenderTexture(); if (pRet.initWithWidthAndHeight(w, h, eFormat)) { return(pRet); } return(null); }
/// <summary> /// creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> public static CCRenderTexture renderTextureWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { CCRenderTexture pRet = new CCRenderTexture(); if (pRet.initWithWidthAndHeight(w, h, eFormat)) { return pRet; } return null; }
/// <summary> /// creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> /// <param name="w"></param> /// <param name="h"></param> /// <param name="eFormat"></param> /// <returns></returns> public static CCRenderTexture renderTextureWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { CCRenderTexture pRet = new CCRenderTexture(); if (pRet != null && pRet.initWithWidthAndHeight(w, h, eFormat)) { //pRet->autorelease(); return pRet; } //CC_SAFE_DELETE(pRet); return null; }
public override void onEnter() { base.onEnter(); // create a transparent color layer // in which we are going to add our rendertextures CCSize size = CCDirector.sharedDirector().getWinSize(); // create the second render texture for outScene CCRenderTexture outTexture = CCRenderTexture.renderTextureWithWidthAndHeight((int)size.width, (int)size.height); if (outTexture == null) { return; } outTexture.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); outTexture.position = new CCPoint(size.width / 2, size.height / 2); outTexture.anchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer outTexture.clear(0, 0, 0, 1); outTexture.begin(); m_pOutScene.visit(); outTexture.end(); // Since we've passed the outScene to the texture we don't need it. this.hideOutShowIn(); // We need the texture in RenderTexture. CCProgressTimer outNode = CCProgressTimer.progressWithTexture(outTexture.Sprite.Texture); // but it's flipped upside down so we flip the sprite //outNode.Sprite.->setFlipY(true); // Return the radial type that we want to use outNode.Type = radialType(); outNode.Percentage = 100.0f; outNode.position = new CCPoint(size.width / 2, size.height / 2); outNode.anchorPoint = new CCPoint(0.5f, 0.5f); // create the blend action CCAction layerAction = CCSequence.actions ( CCProgressFromTo.actionWithDuration(m_fDuration, 100.0f, 0.0f), CCCallFunc.actionWithTarget(this, base.finish) ); // run the blend action outNode.runAction(layerAction); // add the layer (which contains our two rendertextures) to the scene this.addChild(outNode, 2, kSceneRadial); }
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 = new CCLayerColor(new CCColor4B(200, 200, 200, 255)); AddChild(background); CCSprite spr_premulti = new CCSprite("Images/fire"); spr_premulti.Position = new CCPoint(16, 48); CCSprite spr_nonpremulti = new CCSprite("Images/fire"); spr_nonpremulti.Position = new CCPoint(16, 16); /* A2 & B2 setup */ CCRenderTexture rend = new CCRenderTexture(32, 64); // It's possible to modify the RenderTexture blending function by //CCBlendFunc bf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); //rend.Sprite.BlendFunc = bf; rend.Begin(); // A2 spr_premulti.Visit(); // B2 spr_nonpremulti.Visit(); rend.End(); CCSize s = CCDirector.SharedDirector.WinSize; /* 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 CCTexture2D CreateCharacterTexture() { const int width = 490; const int height = 278; var centerPoint = new CCPoint(width / 2, height / 2); var characterTexture = new CCRenderTexture(width, height); characterTexture.BeginWithClear(100, 0, 0, 0); var bodySprite = CreateCustomisationSprite(); bodySprite.Position = centerPoint; bodySprite.Visit(); var armorSprite = CreateCustomisationSprite(); armorSprite.Position = centerPoint; armorSprite.Visit(); var eyesSprite = CreateCustomisationSprite(); eyesSprite.Position = centerPoint; eyesSprite.Visit(); var noseSprite = CreateCustomisationSprite(); noseSprite.Position = centerPoint; noseSprite.Visit(); var hairSprite = CreateCustomisationSprite(); hairSprite.Position = centerPoint; hairSprite.Visit(); var moustacheSprite = CreateCustomisationSprite(); moustacheSprite.Position = centerPoint; moustacheSprite.Visit(); var beardSprite = CreateCustomisationSprite(); beardSprite.Position = centerPoint; beardSprite.Visit(); var helmutSprite = CreateCustomisationSprite(); helmutSprite.Position = centerPoint; helmutSprite.Visit(); var weaponSprite = CreateCustomisationSprite(); weaponSprite.Position = centerPoint; weaponSprite.Visit(); characterTexture.End(); return characterTexture.Sprite.Texture; }
public override void onEnter() { base.onEnter(); ccColor4B _ccColor4B = new ccColor4B(0, 0, 0, 0); CCSize winSize = CCDirector.sharedDirector().getWinSize(); CCLayer cCLayer = new CCLayer(); CCRenderTexture cCPoint = CCRenderTexture.renderTextureWithWidthAndHeight((int)winSize.width, (int)winSize.height); if (cCPoint == null) { return; } cCPoint.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); cCPoint.position = new CCPoint(winSize.width / 2f, winSize.height / 2f); cCPoint.anchorPoint = new CCPoint(0.5f, 0.5f); cCPoint.begin(); this.m_pInScene.visit(); cCPoint.end(); CCRenderTexture cCRenderTexture = CCRenderTexture.renderTextureWithWidthAndHeight((int)winSize.width, (int)winSize.height); cCRenderTexture.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); cCRenderTexture.position = new CCPoint(winSize.width / 2f, winSize.height / 2f); cCRenderTexture.anchorPoint = new CCPoint(0.5f, 0.5f); cCRenderTexture.begin(); this.m_pOutScene.visit(); cCRenderTexture.end(); ccBlendFunc _ccBlendFunc = new ccBlendFunc(1, 1); ccBlendFunc _ccBlendFunc1 = new ccBlendFunc(770, 771); cCPoint.Sprite.BlendFunc = _ccBlendFunc; cCRenderTexture.Sprite.BlendFunc = _ccBlendFunc1; cCLayer.addChild(cCPoint); cCLayer.addChild(cCRenderTexture); cCPoint.Sprite.Opacity = 255; cCRenderTexture.Sprite.Opacity = 255; CCFiniteTimeAction[] cCFiniteTimeActionArray = new CCFiniteTimeAction[] { CCFadeTo.actionWithDuration(this.m_fDuration, 0), CCCallFunc.actionWithTarget(this, new SEL_CallFunc(this.hideOutShowIn)), CCCallFunc.actionWithTarget(this, new SEL_CallFunc(this.finish)) }; CCAction cCAction = CCSequence.actions(cCFiniteTimeActionArray); cCRenderTexture.Sprite.runAction(cCAction); this.addChild(cCLayer, 2, 2147483647); }
public void renderScreenShot() { var size = CCDirector.SharedDirector.WinSize; var texture = new CCRenderTexture((int)size.Width, (int)size.Height); //var texture = new CCRenderTexture(512, 512); texture.AnchorPoint = new CCPoint(0, 0); texture.Begin(); Visit(); texture.End(); CCSprite sprite = new CCSprite(texture.Sprite.Texture); //sprite.Position = new CCPoint(256, 256); sprite.Position = new CCPoint(size.Width/2, size.Height / 2); sprite.Opacity = 182; //sprite.IsFlipY = true; AddChild(sprite, 999999); sprite.Color = CCTypes.CCGreen; sprite.RunAction( CCSequence.FromActions( new CCFadeTo (2, 0), new CCHide() ) ); }
public static CCRenderTexture Create(int w, int h, SurfaceFormat format, DepthFormat depthFormat, RenderTargetUsage usage) { var pRet = new CCRenderTexture(); pRet.InitWithWidthAndHeight(w, h, format, depthFormat, usage); return pRet; }
public static CCRenderTexture Create(int w, int h, SurfaceFormat format) { var pRet = new CCRenderTexture(); pRet.InitWithWidthAndHeight(w, h, format, DepthFormat.None, RenderTargetUsage.DiscardContents); return pRet; }
public override void onEnter() { base.onEnter(); // create a transparent color layer // in which we are going to add our rendertextures ccColor4B color = new ccColor4B(0, 0, 0, 0); CCSize size = CCDirector.sharedDirector().getWinSize(); //CCLayerColor layer = CCLayerColor.layerWithColor(color); CCLayer layer = new CCLayer(); // create the first render texture for inScene CCRenderTexture inTexture = CCRenderTexture.renderTextureWithWidthAndHeight((int)size.width, (int)size.height); if (null == inTexture) { return; } inTexture.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); inTexture.position = new CCPoint(size.width / 2, size.height / 2); inTexture.anchorPoint = new CCPoint(0.5f, 0.5f); // render inScene to its texturebuffer inTexture.begin(); m_pInScene.visit(); inTexture.end(); // create the second render texture for outScene CCRenderTexture outTexture = CCRenderTexture.renderTextureWithWidthAndHeight((int)size.width, (int)size.height); outTexture.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); outTexture.position = new CCPoint(size.width / 2, size.height / 2); outTexture.anchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer outTexture.begin(); m_pOutScene.visit(); outTexture.end(); // create blend functions ccBlendFunc blend1 = new ccBlendFunc(OGLES.GL_ONE, OGLES.GL_ONE); // inScene will lay on background and will not be used with alpha ccBlendFunc blend2 = new ccBlendFunc(OGLES.GL_SRC_ALPHA, OGLES.GL_ONE_MINUS_SRC_ALPHA); // we are going to blend outScene via alpha // set blendfunctions inTexture.Sprite.BlendFunc = blend1; outTexture.Sprite.BlendFunc = blend2; // add render textures to the layer layer.addChild(inTexture); layer.addChild(outTexture); // initial opacity: inTexture.Sprite.Opacity = 255; outTexture.Sprite.Opacity = 255; // create the blend action CCAction layerAction = CCSequence.actions ( CCFadeTo.actionWithDuration(m_fDuration, 0), CCCallFunc.actionWithTarget(this, (base.hideOutShowIn)), CCCallFunc.actionWithTarget(this, (base.finish)) ); //// run the blend action outTexture.Sprite.runAction(layerAction); // add the layer (which contains our two rendertextures) to the scene addChild(layer, 2, kSceneFade); }
public void NeedsLayout() { m_pOnSprite.Position = new CCPoint(m_pOnSprite.ContentSize.Width / 2 + m_fSliderXPosition, m_pOnSprite.ContentSize.Height / 2); m_pOffSprite.Position = new CCPoint(m_pOnSprite.ContentSize.Width + m_pOffSprite.ContentSize.Width / 2 + m_fSliderXPosition, m_pOffSprite.ContentSize.Height / 2); m_ThumbSprite.Position = new CCPoint(m_pOnSprite.ContentSize.Width + m_fSliderXPosition, m_pMaskTexture.ContentSize.Height / 2); if (m_pOnLabel != null) { m_pOnLabel.Position = new CCPoint(m_pOnSprite.Position.X - m_ThumbSprite.ContentSize.Width / 6, m_pOnSprite.ContentSize.Height / 2); } if (m_pOffLabel != null) { m_pOffLabel.Position = new CCPoint(m_pOffSprite.Position.X + m_ThumbSprite.ContentSize.Width / 6, m_pOffSprite.ContentSize.Height / 2); } CCRenderTexture rt = new CCRenderTexture((int) m_pMaskTexture.ContentSize.Width, (int) m_pMaskTexture.ContentSize.Height, SurfaceFormat.Color, DepthFormat.None, RenderTargetUsage.DiscardContents); rt.BeginWithClear(0, 0, 0, 0); m_pOnSprite.Visit(); m_pOffSprite.Visit(); if (m_pOnLabel != null) { m_pOnLabel.Visit(); } if (m_pOffLabel != null) { m_pOffLabel.Visit(); } if (m_pMaskSprite == null) { m_pMaskSprite = new CCSprite(m_pMaskTexture); m_pMaskSprite.AnchorPoint = new CCPoint(0, 0); m_pMaskSprite.BlendFunc = new CCBlendFunc(OGLES.GL_ZERO, OGLES.GL_SRC_ALPHA); } else { m_pMaskSprite.Texture = m_pMaskTexture; } m_pMaskSprite.Visit(); rt.End(); Texture = rt.Sprite.Texture; //IsFlipY = true; }