Ejemplo n.º 1
0
        public bool initWithSize(ccGridSize gridSize)
        {
            CCDirector pDirector = CCDirector.sharedDirector();
            CCSize     s         = pDirector.winSizeInPixels;

            ulong POTWide = ccNextPOT((uint)s.width);
            ulong POTHigh = ccNextPOT((uint)s.height);

            // we only use rgba8888
            CCTexture2DPixelFormat format = CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888;

            CCTexture2D pTexture = new CCTexture2D();

            pTexture.initWithData(null, format, (uint)POTWide, (uint)POTHigh, s);

            if (pTexture == null)
            {
                CCLog.Log("cocos2d: CCGrid: error creating texture");
                return(false);
            }

            initWithSize(gridSize, pTexture, false);

            return(true);
        }
Ejemplo n.º 2
0
        public bool initWithSize(ccGridSize gridSize)
        {
            CCSize cCSize = CCDirector.sharedDirector().winSizeInPixels;
            ulong  num    = this.ccNextPOT((ulong)((uint)cCSize.width));
            ulong  num1   = this.ccNextPOT((ulong)((uint)cCSize.height));
            CCTexture2DPixelFormat cCTexture2DPixelFormat = CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888;
            CCTexture2D            cCTexture2D            = new CCTexture2D();

            cCTexture2D.initWithData(null, cCTexture2DPixelFormat, (uint)num, (uint)num1, cCSize);
            if (cCTexture2D == null)
            {
                CCLog.Log("cocos2d: CCGrid: error creating texture");
                return(false);
            }
            this.initWithSize(gridSize, cCTexture2D, false);
            return(true);
        }
Ejemplo n.º 3
0
        public bool initWithSize(ccGridSize gridSize)
        {
            CCDirector pDirector = CCDirector.sharedDirector();
            CCSize s = pDirector.winSizeInPixels;

            ulong POTWide = ccNextPOT((uint)s.width);
            ulong POTHigh = ccNextPOT((uint)s.height);

            // we only use rgba8888
            CCTexture2DPixelFormat format = CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888;

            CCTexture2D pTexture = new CCTexture2D();
            pTexture.initWithData(null, format, (uint)POTWide, (uint)POTHigh, s);

            if (pTexture == null)
            {
                CCLog.Log("cocos2d: CCGrid: error creating texture");
                return false;
            }

            initWithSize(gridSize, pTexture, false);

            return true;
        }
Ejemplo n.º 4
0
        /// <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;
        }