Exemplo n.º 1
0
	void CCGrabber::grab(cocos2d::CCTexture2D *pTexture)
	{
		// If the gles version is lower than GLES_VER_1_0, 
		// all the functions in CCGrabber return directly.
		if (m_eGlesVersion <= GLES_VER_1_0)
		{
			return ;
		}

		glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO);

		// bind
		ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_fbo);

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

		// check if it worked (probably worth doing :) )
		GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER);
		if (status != CC_GL_FRAMEBUFFER_COMPLETE)
		{
			CCLOG("Frame Grabber: could not attach texture to frmaebuffer");
		}

		ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_oldFBO);
	}
Exemplo n.º 2
0
bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat)
{
    bool bRet = false;
    do 
    {
        w *= (int)CC_CONTENT_SCALE_FACTOR();
        h *= (int)CC_CONTENT_SCALE_FACTOR();

        glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &m_nOldFBO);

        // textures must be power of two squared
        unsigned int powW = ccNextPOT(w);
        unsigned int powH = ccNextPOT(h);

        void *data = malloc((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, CCSizeMake((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->setScaleY(-1);
        this->addChild(m_pSprite);

        ccBlendFunc tBlendFunc = {GL_ONE, GL_ONE_MINUS_SRC_ALPHA };
        m_pSprite->setBlendFunc(tBlendFunc);

        ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO);
        bRet = true;
    } while (0);
    return bRet;
    
}
Exemplo n.º 3
0
	void CCGrabber::grab(cocos2d::CCTexture2D *pTexture)
	{
		glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_oldFBO);

		// bind
		ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_fbo);

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

		// check if it worked (probably worth doing :) )
		GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER);
		if (status != CC_GL_FRAMEBUFFER_COMPLETE)
		{
			CCLOG("Frame Grabber: could not attach texture to frmaebuffer");
		}

		ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_oldFBO);
	}