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 = CCDrawManager.DepthStencilState; CCDrawManager.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(); CCDrawManager.DepthStencilState = new DepthStencilState() { DepthBufferEnable = false, StencilEnable = true, StencilFunction = CompareFunction.NotEqual, StencilPass = StencilOperation.Keep, ReferenceStencil = 1 }; // GL_SRC_ALPHA CCDrawManager.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(); CCDrawManager.DepthStencilState = save; rend.End(); rend.Position = new CCPoint(s.Width * 0.5f, s.Height * 0.5f); AddChild(rend); }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; CCSprite sprite = new CCSprite("Images/fire"); sprite.Position = new CCPoint(windowSize.Width * 0.25f, 0); sprite.Scale = 10; CCRenderTexture rend = new CCRenderTexture(windowSize, windowSize, CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8, CCRenderTargetUsage.DiscardContents); rend.BeginWithClear(0, 0, 0, 0, 0); // var save = CCDrawManager.SharedDrawManager.DepthStencilState; // // CCDrawManager.SharedDrawManager.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(); // CCDrawManager.SharedDrawManager.DepthStencilState = new DepthStencilState() // { // DepthBufferEnable = false, // StencilEnable = true, // StencilFunction = CompareFunction.NotEqual, // StencilPass = StencilOperation.Keep, // ReferenceStencil = 1 // }; // CCDrawManager.SharedDrawManager.BlendFunc(new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE_MINUS_SRC_ALPHA)); sprite.Position = sprite.Position + new CCPoint(sprite.ContentSize.Width * sprite.ScaleX, sprite.ContentSize.Height * sprite.ScaleY) * 0.5f; sprite.Visit(); // CCDrawManager.SharedDrawManager.DepthStencilState = save; rend.End(); rend.Position = new CCPoint(windowSize.Width * 0.5f, windowSize.Height * 0.5f); AddChild(rend); }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; spritePremulti.Position = new CCPoint(16, 48); spriteNonpremulti.Position = new CCPoint(16, 16); CCSize rendSize = new CCSize(32, 64); /* A2 & B2 setup */ CCRenderTexture rend = new CCRenderTexture(rendSize, rendSize); // 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 spritePremulti.Visit(); // B2 spriteNonpremulti.Visit(); rend.End(); /* A1: setup */ spritePremulti.Position = new CCPoint(windowSize.Width / 2 - 16, windowSize.Height / 2 + 16); /* B1: setup */ spriteNonpremulti.Position = new CCPoint(windowSize.Width / 2 - 16, windowSize.Height / 2 - 16); rend.Position = new CCPoint(windowSize.Width / 2 + 16, windowSize.Height / 2); AddChild(spriteNonpremulti); AddChild(spritePremulti); AddChild(rend); }
public Button(CCSprite sprite, CCLabel label) : this() { this.ContentSize = sprite.ScaledContentSize; sprite.AnchorPoint = CCPoint.AnchorLowerLeft; label.Position = sprite.ContentSize.Center; // Create the render texture to draw to. It will be the size of the button background sprite var render = new CCRenderTexture(sprite.ContentSize, sprite.ContentSize); // Clear it to any background color you want render.BeginWithClear(CCColor4B.Transparent); // Render the background sprite to the render texture sprite.Visit(); // Render the label to the render texture label.Visit(); // End the rendering render.End(); // Add the button sprite to this node so it can be rendered buttonSprite = render.Sprite; buttonSprite.AnchorPoint = CCPoint.AnchorMiddle; AddChild(this.buttonSprite); }
public SpriteWithColor(CCColor4B bgColor, CCSize textureSizeInPixels) : base() { // 1: Create new CCRenderTexture CCRenderTexture rt = new CCRenderTexture(textureSizeInPixels, textureSizeInPixels); // 2: Call CCRenderTexture:begin rt.BeginWithClear(bgColor); // 3: Draw into the texture // You'll add this later GenerateGradient(textureSizeInPixels); var noise = new CCSprite("images/Noise.png"); noise.AnchorPoint = CCPoint.AnchorLowerLeft; noise.Position = CCPoint.Zero; noise.BlendFunc = new CCBlendFunc(CCOGLES.GL_DST_COLOR, CCOGLES.GL_ZERO); noise.Texture.SamplerState = Microsoft.Xna.Framework.Graphics.SamplerState.LinearWrap; // To get the linear wrap to work correctly we have to set the TextureRectInPixels as well as ContentSize noise.TextureRectInPixels = new CCRect(0, 0, textureSizeInPixels.Width, textureSizeInPixels.Height); noise.ContentSize = noise.TextureRectInPixels.Size; noise.Visit(); // 4: Call CCRenderTexture:end rt.End(); this.Texture = rt.Texture; }
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 override void Visit(ref CCAffineTransform parentWorldTransform) { if (positionsAreDirty) { UpdatePositions(); AdjustScale9ImagePosition(); positionsAreDirty = false; } var localTransform = AffineLocalTransform; var worldTransform = CCAffineTransform.Identity; CCAffineTransform.Concat(ref localTransform, ref parentWorldTransform, out worldTransform); if (isScale9Enabled) { for (var j = 0; j < protectedChildren.Count; j++) { var node = protectedChildren[j] as CCSprite; if (node != null) { node.Visit(ref worldTransform); } else { break; } } } else { if (scale9Image != null) { scale9Image.Visit(ref worldTransform); } } base.Visit(ref parentWorldTransform); }
void OnTouchesMoved(List <CCTouch> touches, CCEvent touchEvent) { CCAffineTransform worldTransform = AffineWorldTransform; CCTouch touch = touches[0]; CCPoint start = touch.Location; CCPoint end = touch.PreviousLocation; // begin drawing to the render texture target.Begin(); // for extra points, we'll draw this smoothly from the last position and vary the sprite's // scale/rotation/offset float distance = CCPoint.Distance(start, end); if (distance > 1) { var d = (int)distance; for (int i = 0; i < d; i++) { float difx = end.X - start.X; float dify = end.Y - start.Y; float delta = i / distance; brush.Position = new CCPoint(start.X + (difx * delta), start.Y + (dify * delta)); brush.Rotation = CCRandom.Next() % 360; float r = (CCRandom.Next() % 50 / 50f) + 0.25f; brush.Scale = r; // Comment out the following line to show just the initial red color set brush.Color = new CCColor3B((byte)(CCRandom.Next() % 127 + 128), 255, 255); // Call visit to draw the brush, don't call draw.. brush.Visit(ref worldTransform); } } // finish drawing and return context back to the screen target.End(); }
public StripeWithColor(CCColor4B c1, CCColor4B c2, CCSize textureSizeInPixels, int nStripes) : base() { // 1: Create new CCRenderTexture CCRenderTexture rt = new CCRenderTexture(textureSizeInPixels, textureSizeInPixels); // 2: Call CCRenderTexture:begin rt.BeginWithClear(c1); // 3: Draw into the texture // You'll add this later GenerateStripes(textureSizeInPixels, c2, nStripes); var noise = new CCSprite("images/Noise.png"); noise.AnchorPoint = CCPoint.AnchorLowerLeft; noise.BlendFunc = new CCBlendFunc(CCOGLES.GL_DST_COLOR, CCOGLES.GL_ZERO); noise.Visit(); // 4: Call CCRenderTexture:end rt.End(); this.Texture = rt.Texture; }