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(CCOGLES.GL_ONE, CCOGLES.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 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(CCOGLES.GL_ZERO, CCOGLES.GL_SRC_ALPHA); } else { m_pMaskSprite.Texture = m_pMaskTexture; } m_pMaskSprite.Visit(); rt.End(); Texture = rt.Sprite.Texture; //IsFlipY = true; }
public void NeedsLayout() { _onSprite.Position = new CCPoint(_onSprite.ContentSize.Width / 2 + _sliderXPosition, _onSprite.ContentSize.Height / 2); _offSprite.Position = new CCPoint(_onSprite.ContentSize.Width + _offSprite.ContentSize.Width / 2 + _sliderXPosition, _offSprite.ContentSize.Height / 2); _thumbSprite.Position = new CCPoint(_onSprite.ContentSize.Width + _sliderXPosition, _maskSprite.ContentSize.Height / 2); if (_onLabel != null) { _onLabel.Position = new CCPoint(_onSprite.Position.X - _thumbSprite.ContentSize.Width / 6, _onSprite.ContentSize.Height / 2); } if (_offLabel != null) { _offLabel.Position = new CCPoint(_offSprite.Position.X + _thumbSprite.ContentSize.Width / 6, _offSprite.ContentSize.Height / 2); } var rt = new CCRenderTexture( (int)_maskSprite.ContentSizeInPixels.Width, (int)_maskSprite.ContentSizeInPixels.Height, SurfaceFormat.Color, DepthFormat.None, RenderTargetUsage.DiscardContents ); rt.BeginWithClear(0, 0, 0, 0); _onSprite.Visit(); _offSprite.Visit(); if (_onLabel != null) { _onLabel.Visit(); } if (_offLabel != null) { _offLabel.Visit(); } _maskSprite.AnchorPoint = new CCPoint(0, 0); _maskSprite.BlendFunc = new CCBlendFunc(CCOGLES.GL_ZERO, CCOGLES.GL_SRC_ALPHA); _maskSprite.Visit(); rt.End(); InitWithTexture(rt.Sprite.Texture); ContentSize = _maskSprite.ContentSize; }
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); }
private void InitClipping() { if (m_childClippingMode == CCClipMode.BoundsWithRenderTarget) { if (m_pRenderTexture == null || m_pRenderTexture.ContentSize.Width < ContentSize.Width || m_pRenderTexture.ContentSize.Height < ContentSize.Height) { m_pRenderTexture = new CCRenderTexture((int)ContentSize.Width, (int)ContentSize.Height); m_pRenderTexture.Sprite.AnchorPoint = new CCPoint(0, 0); } m_pRenderTexture.Sprite.TextureRect = new CCRect(0, 0, ContentSize.Width, ContentSize.Height); } else { m_pRenderTexture = null; } }
public DrawPrimitivesWithRenderTextureTest() { CCSize s = CCDirector.SharedDirector.WinSize; CCRenderTexture text = new CCRenderTexture((int)s.Width, (int)s.Height); CCDrawNode draw = new CCDrawNode(); text.AddChild(draw, 10); text.Begin(); // Draw polygons CCPoint[] points = new CCPoint[] { new CCPoint(s.Height / 4, 0), new CCPoint(s.Width, s.Height / 5), new CCPoint(s.Width / 3 * 2, s.Height) }; draw.DrawPolygon(points, points.Length, new CCColor4F(1, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1)); text.End(); AddChild(text, 24); }
public RenderTextureSave() { CCSize s = CCDirector.SharedDirector.WinSize; // create a render texture, this is what we are going to draw into m_pTarget = new CCRenderTexture((int) s.Width, (int) s.Height, SurfaceFormat.Color, DepthFormat.None, RenderTargetUsage.PreserveContents); // Let's clear the rendertarget here so that we start off fresh. // Some platforms do not seem to be initializing the rendertarget color so this will make sure the background shows up colored instead of // what looks like non initialized. Mostly MacOSX for now. m_pTarget.Clear(0,0,0,255); 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 (CCOGLES.GL_ONE, CCOGLES.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 = new CCMenuItemFont("Save Image", saveImage); CCMenuItem item2 = new CCMenuItemFont("Clear", clearImage); var menu = new CCMenu(item1, item2); AddChild(menu); menu.AlignItemsVertically(); menu.Position = new CCPoint(s.Width - 80, s.Height - 30); }
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 void NeedsLayout() { _onSprite.Position = new CCPoint(_onSprite.ContentSize.Width / 2 + _sliderXPosition, _onSprite.ContentSize.Height / 2); _offSprite.Position = new CCPoint(_onSprite.ContentSize.Width + _offSprite.ContentSize.Width / 2 + _sliderXPosition, _offSprite.ContentSize.Height / 2); _thumbSprite.Position = new CCPoint(_onSprite.ContentSize.Width + _sliderXPosition, _maskTexture.ContentSize.Height / 2); if (_onLabel != null) { _onLabel.Position = new CCPoint(_onSprite.Position.X - _thumbSprite.ContentSize.Width / 6, _onSprite.ContentSize.Height / 2); } if (_offLabel != null) { _offLabel.Position = new CCPoint(_offSprite.Position.X + _thumbSprite.ContentSize.Width / 6, _offSprite.ContentSize.Height / 2); } CCRenderTexture rt = new CCRenderTexture((int) _maskTexture.ContentSize.Width, (int) _maskTexture.ContentSize.Height, SurfaceFormat.Color, DepthFormat.None, RenderTargetUsage.DiscardContents); rt.BeginWithClear(0, 0, 0, 0); _onSprite.Visit(); _offSprite.Visit(); if (_onLabel != null) { _onLabel.Visit(); } if (_offLabel != null) { _offLabel.Visit(); } if (_maskSprite == null) { _maskSprite = new CCSprite(_maskTexture); _maskSprite.AnchorPoint = new CCPoint(0, 0); _maskSprite.BlendFunc = new CCBlendFunc(CCOGLES.GL_ZERO, CCOGLES.GL_SRC_ALPHA); } else { _maskSprite.Texture = _maskTexture; } _maskSprite.Visit(); rt.End(); Texture = rt.Sprite.Texture; //IsFlipY = true; }
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; }