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;
        }
Beispiel #2
0
 public CCMotionStreak()
 {
     m_tBlendFunc = new ccBlendFunc();
     m_tBlendFunc.src = 0;// CC_BLEND_SRC;
     m_tBlendFunc.dst = 0x0303;// CC_BLEND_DST;
     m_tOpacity = 0xff; // Fully opaque
 }
Beispiel #3
0
        public override void onEnter()
        {
            base.onEnter();

            CCActionInterval effect = (CCActionInterval)(CCSequence.actions(CCDelayTime.actionWithDuration(2.0f), CCShaky3D.actionWithRange(16, false, new ccGridSize(5, 5), 5.0f)));

            // cleanup
            CCNode bg = getChildByTag(EffectAdvanceScene.kTagBackground);
            removeChild(bg, true);

            // background
            CCLayerColor layer = CCLayerColor.layerWithColor(new ccColor4B(255, 0, 0, 255));
            addChild(layer, -10);
            CCSprite sprite = CCSprite.spriteWithFile("Images/grossini");
            sprite.position = new CCPoint(50, 80);
            layer.addChild(sprite, 10);

            // foreground
            CCLayerColor layer2 = CCLayerColor.layerWithColor(new ccColor4B(0, 255, 0, 255));
            CCSprite fog = CCSprite.spriteWithFile("Images/Fog");

            ccBlendFunc bf = new ccBlendFunc { src = 0x0302, dst = 0x0303 };
            fog.BlendFunc = bf;
            layer2.addChild(fog, 1);
            addChild(layer2, 1);

            layer2.runAction(CCRepeatForever.actionWithAction(effect));
        }
 public CCLayerColor()
 {
     m_cOpacity = 0;
     m_tColor = new ccColor3B(0, 0, 0);
     // default blend function
     m_tBlendFunc = new ccBlendFunc();
     m_tBlendFunc.src = 1;
     m_tBlendFunc.dst = 0x0303;
 }
        public void newBlend(float dt)
        {
            CCLayerColor layer = (CCLayerColor)getChildByTag(kTagLayer);

            int src;
            int dst;

            if (layer.BlendFunc.dst == GL_ZERO)
            {
                src = 1;
                dst = 0x0303;
            }
            else
            {
                src = 0x0307;
                dst = GL_ZERO;
            }

            ccBlendFunc bf = new ccBlendFunc(src, dst);
            layer.BlendFunc = (bf);
        }
 public CCParticleSystem()
 {
     m_sPlistFile = "";
     m_fElapsed = 0;
     m_pParticles = null;
     m_fEmitCounter = 0;
     m_uParticleIdx = 0;
     #if CC_ENABLE_PROFILERS
     m_pProfilingTimer = NULL;
     #endif
     m_bIsActive = true;
     m_uParticleCount = 0;
     m_fDuration = 0;
     m_tSourcePosition = new CCPoint(0,0);
     m_tPosVar = new CCPoint(0,0);
     m_fLife = 0;
     m_fLifeVar = 0;
     m_fAngle = 0;
     m_fAngleVar = 0;
     m_fStartSize = 0;
     m_fStartSizeVar = 0;
     m_fEndSize = 0;
     m_fEndSizeVar = 0;
     m_fStartSpin = 0;
     m_fStartSpinVar = 0;
     m_fEndSpin = 0;
     m_fEndSpinVar = 0;
     m_fEmissionRate = 0;
     m_uTotalParticles = 0;
     m_pTexture = null;
     m_bIsBlendAdditive = false;
     m_ePositionType = eParticlePositionType.kCCPositionTypeFree;
     m_bIsAutoRemoveOnFinish = false;
     m_nEmitterMode = (int)eParticleMode.kCCParticleModeGravity;
     modeA = new sModeA();
     modeA.gravity = new CCPoint(0,0);
     modeA.speed = 0;
     modeA.speedVar = 0;
     modeA.tangentialAccel = 0;
     modeA.tangentialAccelVar = 0;
     modeA.radialAccel = 0;
     modeA.radialAccelVar = 0;
     modeB = new sModeB();
     modeB.startRadius = 0;
     modeB.startRadiusVar = 0;
     modeB.endRadius = 0;
     modeB.endRadiusVar = 0;
     modeB.rotatePerSecond = 0;
     modeB.rotatePerSecondVar = 0;
     m_tBlendFunc = new ccBlendFunc();
     m_tBlendFunc.src = 0;// CC_BLEND_SRC;
     m_tBlendFunc.dst = 0x0303;// CC_BLEND_DST;
 }
 public CCAtlasNode()
 {
     m_tBlendFunc = new ccBlendFunc();
 }
Beispiel #8
0
        public virtual bool init()
        {
            m_bDirty = m_bRecursiveDirty = false;

            // by default use "Self Render".
            // if the sprite is added to an batchnode, then it will automatically switch to "SpriteSheet Render"
            useSelfRender();

            m_bOpacityModifyRGB = true;
            m_nOpacity = 255;
            m_sColor = new ccColor3B(255, 255, 255);
            m_sColorUnmodified = new ccColor3B(255, 255, 255);

            m_sBlendFunc = new ccBlendFunc();
            m_sBlendFunc.src = ccMacros.CC_BLEND_SRC;
            m_sBlendFunc.dst = ccMacros.CC_BLEND_DST;

            // update texture (calls updateBlendFunc)
            Texture = null;

            // clean the Quad
            m_sQuad = new ccV3F_C4B_T2F_Quad();

            m_bFlipX = m_bFlipY = false;

            // default transform anchor: center
            AnchorPoint = (CCPointExtension.ccp(0.5f, 0.5f));

            // zwoptex default values
            m_obOffsetPositionInPixels = new CCPoint();

            m_eHonorParentTransform = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;
            m_bHasChildren = false;

            // Atlas: Color
            ccColor4B tmpColor = new ccColor4B(255, 255, 255, 255);
            m_sQuad.bl.colors = tmpColor;
            m_sQuad.br.colors = tmpColor;
            m_sQuad.tl.colors = tmpColor;
            m_sQuad.tr.colors = tmpColor;

            // Atlas: Vertex

            // updated in "useSelfRender"

            // Atlas: TexCoords

            setTextureRectInPixels(new CCRect(), false, new CCSize());

            return true;
        }
        /// <summary>
        ///  initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid 
        /// </summary>
        public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat)
        {
            // If the gles version is lower than GLES_VER_1_0,
            // some extended gles functions can't be implemented, so return false directly.
            if (CCConfiguration.sharedConfiguration().getGlesVersion() <= CCGlesVersion.GLES_VER_1_0)
            {
                return false;
            }

            bool bRet = false;
            do
            {
                w *= (int)CCDirector.sharedDirector().ContentScaleFactor;
                h *= (int)CCDirector.sharedDirector().ContentScaleFactor;

                //glGetIntegerv(0x8CA6, m_nOldFBO);

                // textures must be power of two squared
                uint powW = (uint)ccUtils.ccNextPOT(w);
                uint powH = (uint)ccUtils.ccNextPOT(h);

                m_pTexture = new CCTexture2D();

                CCApplication app = CCApplication.sharedApplication();
                m_RenderTarget2D = new RenderTarget2D(app.GraphicsDevice, (int)w, (int)h);
                app.GraphicsDevice.SetRenderTarget(m_RenderTarget2D);
                app.GraphicsDevice.Clear(new Microsoft.Xna.Framework.Color(0, 0, 0, 0));

                m_pTexture.initWithTexture(m_RenderTarget2D);

                // generate FBO
                //ccglGenFramebuffers(1, &m_uFBO);
                //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);

                // associate texture with FBO
                //ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0);

                // check if it worked (probably worth doing :) )
                //GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER);
                //if (status != CC_GL_FRAMEBUFFER_COMPLETE)
                //{
                //    CCAssert(0, "Render Texture : Could not attach texture to framebuffer");
                //    CC_SAFE_DELETE(m_pTexture);
                //    break;
                //}

                //m_pTexture.setAliasTexParameters();

                m_pSprite = CCSprite.spriteWithTexture(m_pTexture);

                //m_pTexture->release();
                //m_pSprite.scaleY = -1;
                this.addChild(m_pSprite);

                ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 };
                m_pSprite.BlendFunc = tBlendFunc;

                //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO);
                bRet = true;
            } while (false);

            return bRet;
        }
        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);
        }
Beispiel #11
0
 public CCAtlasNode()
 {
     this.m_tBlendFunc = new ccBlendFunc();
 }
        /// <summary>
        ///  initializes 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 bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat)
        {
            // If the gles version is lower than GLES_VER_1_0,
            // some extended gles functions can't be implemented, so return false directly.
            if (CCConfiguration.sharedConfiguration().getGlesVersion() <= CCGlesVersion.GLES_VER_1_0)
            {
                return false;
            }

            bool bRet = false;
            do
            {
                w = (int)CCDirector.sharedDirector().ContentScaleFactor;
                h = (int)CCDirector.sharedDirector().ContentScaleFactor;

                //glGetIntegerv(0x8CA6, m_nOldFBO);

                // textures must be power of two squared
                uint powW = (uint)ccUtils.ccNextPOT(w);
                uint powH = (uint)ccUtils.ccNextPOT(h);

                var data = (int)(powW * powH * 4);
                //CC_BREAK_IF(! data);

                //memset(data, 0, (int)(powW * powH * 4));
                //m_ePixelFormat = eFormat;

                m_pTexture = new CCTexture2D();
                //CC_BREAK_IF(! m_pTexture);

                m_pTexture.initWithData(data, (CCTexture2DPixelFormat)m_ePixelFormat, powW, powH, new CCSize((float)w, (float)h));
                //free( data );

                // generate FBO
                //ccglGenFramebuffers(1, &m_uFBO);
                //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);

                // associate texture with FBO
                //ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0);

                // check if it worked (probably worth doing :) )
                //GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER);
                //if (status != CC_GL_FRAMEBUFFER_COMPLETE)
                //{
                //    CCAssert(0, "Render Texture : Could not attach texture to framebuffer");
                //    CC_SAFE_DELETE(m_pTexture);
                //    break;
                //}

                m_pTexture.setAliasTexParameters();

                m_pSprite = CCSprite.spriteWithTexture(m_pTexture);

                //m_pTexture->release();
                m_pSprite.scaleY = -1;
                this.addChild(m_pSprite);

                ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 };
                m_pSprite.BlendFunc = tBlendFunc;

                //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO);
                bRet = true;
            } while (true);
            return bRet;
        }
        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);
        }