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);
        }
        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;
        }
Пример #3
0
        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;
        }