Exemple #1
0
        public virtual void visit()
        {
            Matrix world = CCApplication.sharedApplication().basicEffect.World;

            if (this.m_bIsVisible)
            {
                CCNode node;
                this.m_tCCNodeTransform = Matrix.Identity;
                Matrix matrix2 = Matrix.Identity * CCApplication.sharedApplication().basicEffect.View;
                if ((this.m_pGrid != null) && this.m_pGrid.Active)
                {
                    this.m_pGrid.beforeDraw();
                    this.transformAncestors();
                }
                this.transform();
                int num = 0;
                if ((this.m_pChildren != null) && (this.m_pChildren.Count > 0))
                {
                    while (num < this.m_pChildren.Count)
                    {
                        node = this.m_pChildren[num];
                        if ((node == null) || (node.m_nZOrder >= 0))
                        {
                            break;
                        }
                        Matrix matrix3 = CCApplication.sharedApplication().basicEffect.World;
                        node.visit();
                        CCApplication.sharedApplication().basicEffect.World = matrix3;
                        num++;
                    }
                }
                this.draw();
                if ((this.m_pChildren != null) && (this.m_pChildren.Count > 0))
                {
                    while (num < this.m_pChildren.Count)
                    {
                        node = this.m_pChildren[num];
                        if (node != null)
                        {
                            Matrix matrix4 = CCApplication.sharedApplication().basicEffect.World;
                            node.visit();
                            CCApplication.sharedApplication().basicEffect.World = matrix4;
                        }
                        num++;
                    }
                }
                if ((this.m_pGrid != null) && this.m_pGrid.Active)
                {
                    this.m_pGrid.afterDraw(this);
                }
                CCApplication.sharedApplication().basicEffect.World = world;
                CCApplication.sharedApplication().basicEffect.View = matrix2;
                CCApplication.sharedApplication().viewMatrix = matrix2;
            }
        }
Exemple #2
0
        public override void blit()
        {
            int           mSGridSize = this.m_sGridSize.x * this.m_sGridSize.y;
            CCApplication texture2D  = CCApplication.sharedApplication();

            CCDirector.sharedDirector().getWinSize();
            texture2D.basicEffect.Texture            = this.m_pTexture.getTexture2D();
            texture2D.basicEffect.TextureEnabled     = true;
            texture2D.GraphicsDevice.BlendState      = BlendState.AlphaBlend;
            texture2D.basicEffect.VertexColorEnabled = true;
            List <VertexPositionColorTexture> vertexPositionColorTextures = new List <VertexPositionColorTexture>();

            for (int i = 0; i < mSGridSize; i++)
            {
                ccQuad3 mPVertices       = this.m_pVertices[i];
                ccQuad2 mPTexCoordinates = this.m_pTexCoordinates[i];
                if (mPVertices != null)
                {
                    VertexPositionColorTexture vertexPositionColorTexture = new VertexPositionColorTexture()
                    {
                        Position          = new Vector3(mPVertices.bl.x, mPVertices.bl.y, mPVertices.bl.z),
                        Color             = Color.White,
                        TextureCoordinate = new Vector2(mPTexCoordinates.bl.x, mPTexCoordinates.bl.y)
                    };
                    vertexPositionColorTextures.Add(vertexPositionColorTexture);
                    vertexPositionColorTexture = new VertexPositionColorTexture()
                    {
                        Position          = new Vector3(mPVertices.br.x, mPVertices.br.y, mPVertices.br.z),
                        Color             = Color.White,
                        TextureCoordinate = new Vector2(mPTexCoordinates.br.x, mPTexCoordinates.br.y)
                    };
                    vertexPositionColorTextures.Add(vertexPositionColorTexture);
                    vertexPositionColorTexture = new VertexPositionColorTexture()
                    {
                        Position          = new Vector3(mPVertices.tl.x, mPVertices.tl.y, mPVertices.tl.z),
                        Color             = Color.White,
                        TextureCoordinate = new Vector2(mPTexCoordinates.tl.x, mPTexCoordinates.tl.y)
                    };
                    vertexPositionColorTextures.Add(vertexPositionColorTexture);
                    vertexPositionColorTexture = new VertexPositionColorTexture()
                    {
                        Position          = new Vector3(mPVertices.tr.x, mPVertices.tr.y, mPVertices.tr.z),
                        Color             = Color.White,
                        TextureCoordinate = new Vector2(mPTexCoordinates.tr.x, mPTexCoordinates.tr.y)
                    };
                    vertexPositionColorTextures.Add(vertexPositionColorTexture);
                }
            }
            foreach (EffectPass pass in texture2D.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                texture2D.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, vertexPositionColorTextures.ToArray(), 0, vertexPositionColorTextures.Count, this.m_pIndices, 0, (int)this.m_pIndices.Length / 3);
            }
        }
        public void end()
        {
            CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(null);
            //this.m_pTexture.initWithTexture(this.m_RenderTarget2D);

            //m_pSprite = CCSprite.spriteWithTexture(m_pTexture);
            //this.addChild(m_pSprite);

            //ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 };
            //m_pSprite.BlendFunc = tBlendFunc;
        }
Exemple #4
0
        public override void blit()
        {
            int n = m_sGridSize.x * m_sGridSize.y;

            //////// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
            //////// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY
            //////// Unneeded states: GL_COLOR_ARRAY
            //////glDisableClientState(GL_COLOR_ARRAY);

            //////glVertexPointer(3, GL_FLOAT, 0, m_pVertices);
            //////glTexCoordPointer(2, GL_FLOAT, 0, m_pTexCoordinates);
            //////glDrawElements(GL_TRIANGLES, (GLsizei)n * 6, GL_UNSIGNED_SHORT, m_pIndices);

            //////// restore GL default state
            //////glEnableClientState(GL_COLOR_ARRAY);


            CCApplication app  = CCApplication.sharedApplication();
            CCSize        size = CCDirector.sharedDirector().getWinSize();

            //app.basicEffect.World = app.worldMatrix * TransformUtils.CGAffineToMatrix(this.nodeToWorldTransform());
            app.basicEffect.Texture            = this.m_pTexture.getTexture2D();
            app.basicEffect.TextureEnabled     = true;
            app.GraphicsDevice.BlendState      = BlendState.AlphaBlend;
            app.basicEffect.VertexColorEnabled = true;
            //RasterizerState rs = new RasterizerState();
            //rs.CullMode = CullMode.None;
            //app.GraphicsDevice.RasterizerState = rs;

            List <VertexPositionColorTexture> vertices = new List <VertexPositionColorTexture>();

            for (int i = 0; i < (m_sGridSize.x + 1) * (m_sGridSize.y + 1); i++)
            {
                VertexPositionColorTexture vct = new VertexPositionColorTexture();
                vct.Position          = new Vector3(m_pVertices[i].x, m_pVertices[i].y, m_pVertices[i].z);
                vct.TextureCoordinate = new Vector2(m_pTexCoordinates[i].x, m_pTexCoordinates[i].y);
                vct.Color             = Color.White;
                vertices.Add(vct);
            }

            short[] indexes = m_pIndices;

            foreach (var pass in app.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                app.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(
                    PrimitiveType.TriangleList,
                    vertices.ToArray(), 0, vertices.Count,
                    indexes, 0, indexes.Length / 3);
            }
        }
Exemple #5
0
        protected bool m_bPurgeDirecotorInNextLoop; // this flag will be set to true in end()

        protected void updateContentScaleFactor()
        {
            // [openGLView responseToSelector:@selector(setContentScaleFactor)]
            if (CCApplication.sharedApplication().canSetContentScaleFactor)
            {
                CCApplication.sharedApplication().setContentScaleFactor(m_fContentScaleFactor);
                m_bIsContentScaleSupported = true;
            }
            else
            {
                //CCLOG("cocos2d: setContentScaleFactor:'is not supported on this device");
            }
        }
Exemple #6
0
        public void setOpenGLView()
        {
            this.m_obWinSizeInPoints = CCApplication.sharedApplication().getSize();
            this.m_obWinSizeInPixels = new CCSize(this.m_obWinSizeInPoints.width * this.m_fContentScaleFactor, this.m_obWinSizeInPoints.height * this.m_fContentScaleFactor);
            this.setGLDefaultValues();
            if (this.m_fContentScaleFactor != 1f)
            {
                this.updateContentScaleFactor();
            }
            CCTouchDispatcher cCTouchDispatcher = CCTouchDispatcher.sharedDispatcher();

            CCApplication.sharedApplication().TouchDelegate = cCTouchDispatcher;
            cCTouchDispatcher.IsDispatchEvents = true;
        }
        /// <summary>
        /// Returns a Texture2D object given an file image
        /// If the file image was not previously loaded, it will create a new CCTexture2D
        /// object and it will return it. It will use the filename as a key.
        /// Otherwise it will return a reference of a previosly loaded image.
        /// Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif
        /// </summary>
        public CCTexture2D addImage(string fileimage)
        {
            Debug.Assert(fileimage != null, "TextureCache: fileimage MUST not be NULL");

            CCTexture2D texture;

            lock (m_pDictLock)
            {
                //remove possible -HD suffix to prevent caching the same image twice (issue #1040)
                string pathKey = fileimage;
                //CCFileUtils.ccRemoveHDSuffixFromFile(pathKey);

                bool isTextureExist = m_pTextures.TryGetValue(pathKey, out texture);
                if (!isTextureExist)
                {
                    //int lastPos = fileimage.LastIndexOf("1");
                    //if (lastPos>0)
                    //{
                    //    fileimage = fileimage.Substring(0, lastPos);
                    //}
                    //if (fileimage=="Images/b")
                    //{
                    //    fileimage = fileimage + "1";
                    //}
                    //if (fileimage=="Images/r")
                    //{
                    //    fileimage = fileimage + "1";
                    //}
                    //if (fileimage=="Images/f")
                    //{
                    //    fileimage = fileimage + "1";
                    //}
                    Texture2D textureXna = CCApplication.sharedApplication().content.Load <Texture2D>(fileimage);
                    texture = new CCTexture2D();
                    bool isInited = texture.initWithTexture(textureXna);

                    if (isInited)
                    {
                        m_pTextures.Add(pathKey, texture);
                    }
                    else
                    {
                        Debug.Assert(false, "cocos2d: Couldn't add image:" + fileimage + " in CCTextureCache");
                        return(null);
                    }
                }
            }
            return(texture);
        }
Exemple #8
0
        public override void draw()
        {
            base.draw();

            if (m_pVertexData == null)
            {
                return;
            }

            if (m_pSprite == null)
            {
                return;
            }

            vertices = new VertexPositionColorTexture[m_pVertexData.Length];
            getIndexes();

            for (int i = 0; i < m_pVertexData.Length; i++)
            {
                ccV2F_C4B_T2F temp = m_pVertexData[i];

                vertices[i] = new VertexPositionColorTexture(
                    new Microsoft.Xna.Framework.Vector3(temp.vertices.x, temp.vertices.y, 0),
                    new Microsoft.Xna.Framework.Color(temp.colors.r, temp.colors.g, temp.colors.b, temp.colors.a),
                    new Microsoft.Xna.Framework.Vector2(temp.texCoords.u, temp.texCoords.v));
            }

            CCApplication app = CCApplication.sharedApplication();

            app.basicEffect.Texture        = m_pSprite.Texture.getTexture2D();
            app.basicEffect.TextureEnabled = true;

            VertexDeclaration vertexDeclaration = new VertexDeclaration(new VertexElement[]
            {
                new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Color, 0),
                new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
            });

            foreach (var pass in app.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                app.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(
                    PrimitiveType.TriangleList,
                    vertices, 0, m_nVertexDataCount,
                    indexes, 0, m_nVertexDataCount - 2);
            }
        }
        /// <summary>
        /// starts rendering to the texture while clearing the texture first.
        ///    This is more efficient then calling -clear first and then -begin
        /// </summary>
        public void beginWithClear(float r, float g, float b, float a)
        {
            this.begin();

            CCApplication.sharedApplication().GraphicsDevice.Clear(new Microsoft.Xna.Framework.Color(r, g, b, a));
            // save clear color
            //GLfloat	clearColor[4];
            //glGetFloatv(GL_COLOR_CLEAR_VALUE,clearColor);

            //glClearColor(r, g, b, a);
            //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            //// restore clear color
            //glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
        }
        public void afterRender(ref CCTexture2D pTexture)
        {
            // If the gles version is lower than GLES_VER_1_0,
            // all the functions in CCGrabber return directly.
            if (m_eGlesVersion <= CCGlesVersion.GLES_VER_1_0)
            {
                return;
            }

            CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(null);
            pTexture.Texture = m_RenderTarget2D;

            //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_oldFBO);
            //glColorMask(true, true, true, true);	// #631
        }
Exemple #11
0
        public static void ccDrawLine(CCPoint origin, CCPoint destination, ccColor4F color)
        {
            float contentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor;

            VertexPositionColor[] vertexPositionColor = new VertexPositionColor[] { new VertexPositionColor(new Vector3(origin.x * contentScaleFactor, origin.y * contentScaleFactor, 0f), new Color(color.r, color.g, color.b, color.a)), new VertexPositionColor(new Vector3(destination.x * contentScaleFactor, destination.y * contentScaleFactor, 0f), new Color(color.r, color.g, color.b, color.a)) };
            CCApplication         cCApplication       = CCApplication.sharedApplication();

            cCApplication.basicEffect.TextureEnabled     = false;
            cCApplication.basicEffect.VertexColorEnabled = true;
            foreach (EffectPass pass in cCApplication.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                cCApplication.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertexPositionColor, 0, 1);
            }
        }
        /// <summary>
        /// draws a cubic bezier path
        /// @since v0.8
        /// </summary>
        public static void ccDrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, ccColor4F color)
        {
            VertexPositionColor[] vertices = new VertexPositionColor[segments + 1];
            float         factor           = CCDirector.sharedDirector().ContentScaleFactor;
            CCApplication app = CCApplication.sharedApplication();

            float t = 0;

            for (int i = 0; i < segments; ++i)
            {
                float x = (float)Math.Pow(1 - t, 3) * origin.x + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * destination.x;
                float y = (float)Math.Pow(1 - t, 3) * origin.y + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * destination.y;
                vertices[i]          = new VertexPositionColor();
                vertices[i].Position = new Vector3(x * factor, y * factor, 0);
                vertices[i].Color    = new Color(color.r, color.g, color.b, color.a);
                t += 1.0f / segments;
            }
            vertices[segments] = new VertexPositionColor()
            {
                Color    = new Color(color.r, color.g, color.b, color.a),
                Position = new Vector3(destination.x * factor, destination.y * factor, 0)
            };

            app.basicEffect.TextureEnabled     = false;
            app.basicEffect.VertexColorEnabled = true;
            foreach (var pass in app.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, segments);
            }

            // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
            // Needed states: GL_VERTEX_ARRAY,
            // Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY
            //glDisable(GL_TEXTURE_2D);
            //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
            //glDisableClientState(GL_COLOR_ARRAY);

            //glVertexPointer(2, GL_FLOAT, 0, vertices);
            //glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)segments + 1);
            //delete[] vertices;

            //// restore default state
            //glEnableClientState(GL_COLOR_ARRAY);
            //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            //glEnable(GL_TEXTURE_2D);
        }
Exemple #13
0
        /// <summary>
        /// initializes a CCMenu with it's items
        /// </summary>
        bool initWithItems(params CCMenuItem[] item)
        {
            if (base.init())
            {
                this.m_bIsTouchEnabled = true;

                // menu in the center of the screen
                CCSize s = CCDirector.sharedDirector().getWinSize();

                this.m_bIsRelativeAnchorPoint = false;
                anchorPoint      = new CCPoint(0.5f, 0.5f);
                this.contentSize = s;

                // XXX: in v0.7, winSize should return the visible size
                // XXX: so the bar calculation should be done there
                CCRect r;
                CCApplication.sharedApplication().statusBarFrame(out r);

                ccDeviceOrientation orientation = CCDirector.sharedDirector().deviceOrientation;
                if (orientation == ccDeviceOrientation.CCDeviceOrientationLandscapeLeft
                    ||
                    orientation == ccDeviceOrientation.CCDeviceOrientationLandscapeRight)
                {
                    s.height -= r.size.width;
                }
                else
                {
                    s.height -= r.size.height;
                }

                position = new CCPoint(s.width / 2, s.height / 2);

                if (item != null)
                {
                    foreach (var menuItem in item)
                    {
                        this.addChild(menuItem);
                    }
                }
                //	[self alignItemsVertically];

                m_pSelectedItem = null;
                m_eState        = tCCMenuState.kCCMenuStateWaiting;
                return(true);
            }

            return(false);
        }
Exemple #14
0
        public override void draw()
        {
            base.draw();
            CCApplication application = CCApplication.sharedApplication();

            CCDirector.sharedDirector().getWinSize();
            bool       flag       = (this.m_sBlendFunc.src != ccMacros.CC_BLEND_SRC) || (this.m_sBlendFunc.dst != ccMacros.CC_BLEND_DST);
            BlendState blendState = application.GraphicsDevice.BlendState;

            if (flag)
            {
                BlendState state = new BlendState
                {
                    ColorSourceBlend      = OGLES.GetXNABlend(this.m_sBlendFunc.src),
                    AlphaSourceBlend      = OGLES.GetXNABlend(this.m_sBlendFunc.src),
                    ColorDestinationBlend = OGLES.GetXNABlend(this.m_sBlendFunc.dst),
                    AlphaDestinationBlend = OGLES.GetXNABlend(this.m_sBlendFunc.dst)
                };
                application.GraphicsDevice.BlendState = state;
            }
            if (this.Texture != null)
            {
                application.basicEffect.Texture            = this.Texture.getTexture2D();
                application.basicEffect.TextureEnabled     = true;
                application.basicEffect.Alpha              = ((float)this.Opacity) / 255f;
                application.basicEffect.VertexColorEnabled = true;
            }
            VertexPositionColorTexture[] vertexData = this.m_sQuad.getVertices(ccDirectorProjection.kCCDirectorProjection3D);
            short[] indexData = this.m_sQuad.getIndexes(ccDirectorProjection.kCCDirectorProjection3D);
            foreach (EffectPass pass in application.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                application.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
            }
            application.basicEffect.VertexColorEnabled = false;
            if (flag)
            {
                BlendState state2 = new BlendState
                {
                    ColorSourceBlend      = OGLES.GetXNABlend(ccMacros.CC_BLEND_SRC),
                    AlphaSourceBlend      = OGLES.GetXNABlend(ccMacros.CC_BLEND_SRC),
                    ColorDestinationBlend = OGLES.GetXNABlend(ccMacros.CC_BLEND_DST),
                    AlphaDestinationBlend = OGLES.GetXNABlend(ccMacros.CC_BLEND_DST)
                };
                application.GraphicsDevice.BlendState = state2;
            }
        }
Exemple #15
0
        /// <summary>
        /// Will enable Retina Display on devices that supports it.
        /// It will enable Retina Display on iPhone4 and iPod Touch 4.
        /// It will return YES, if it could enabled it, otherwise it will return NO.
        /// This is the recommened way to enable Retina Display.
        /// @since v0.99.5
        /// </summary>
        public bool enableRetinaDisplay(bool enabled)
        {
            // Already enabled?
            if (enabled && m_fContentScaleFactor == 2)
            {
                return(true);
            }

            // Already diabled?
            if (!enabled && m_fContentScaleFactor == 1)
            {
                return(false);
            }

            // setContentScaleFactor is not supported
            if (!CCApplication.sharedApplication().canSetContentScaleFactor)
            {
                return(false);
            }

            float newScale = (float)(enabled ? 2 : 1);

            CCApplication.sharedApplication().setContentScaleFactor(newScale);

            // release cached texture
            //CCTextureCache::purgeSharedTextureCache();

#if CC_DIRECTOR_FAST_FPS
            //if (m_pFPSLabel)
            //{
            //    CC_SAFE_RELEASE_NULL(m_pFPSLabel);
            //    m_pFPSLabel = CCLabelTTF::labelWithString("00.0", "Arial", 24);
            //    m_pFPSLabel->retain();
            //}
#endif

            if (m_fContentScaleFactor == 2)
            {
                m_bRetinaDisplay = true;
            }
            else
            {
                m_bRetinaDisplay = false;
            }

            return(true);
        }
Exemple #16
0
        public static void ccDrawPoly(CCPoint[] vertices, int numOfVertices, bool closePolygon, bool fill, ccColor4F color)
        {
            VertexPositionColor[] vector3 = new VertexPositionColor[numOfVertices + 1];
            for (int i = 0; i < numOfVertices; i++)
            {
                vector3[i]          = new VertexPositionColor();
                vector3[i].Position = new Vector3(vertices[i].x, vertices[i].y, 0f);
                vector3[i].Color    = new Color(color.r, color.g, color.b, color.a);
            }
            CCApplication rasterizerState = CCApplication.sharedApplication();

            rasterizerState.GraphicsDevice.RasterizerState = new RasterizerState()
            {
                CullMode = CullMode.None
            };
            rasterizerState.basicEffect.TextureEnabled     = false;
            rasterizerState.basicEffect.VertexColorEnabled = true;
            short[] numArray = new short[(numOfVertices - 2) * 3];
            if (!fill)
            {
                if (closePolygon)
                {
                    vector3[numOfVertices] = vector3[0];
                    numOfVertices++;
                }
                foreach (EffectPass pass in rasterizerState.basicEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    rasterizerState.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vector3, 0, numOfVertices - 1);
                }
            }
            else
            {
                for (int j = 0; j < numOfVertices - 2; j++)
                {
                    numArray[j * 3]     = 0;
                    numArray[j * 3 + 1] = (short)(j + 2);
                    numArray[j * 3 + 2] = (short)(j + 1);
                }
                foreach (EffectPass effectPass in rasterizerState.basicEffect.CurrentTechnique.Passes)
                {
                    effectPass.Apply();
                    rasterizerState.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColor>(PrimitiveType.TriangleStrip, vector3, 0, numOfVertices, numArray, 0, numOfVertices - 2);
                }
            }
        }
Exemple #17
0
        public void setOpenGLView()
        {
            // set size
            m_obWinSizeInPoints = CCApplication.sharedApplication().getSize();
            m_obWinSizeInPixels = new CCSize(m_obWinSizeInPoints.width * m_fContentScaleFactor, m_obWinSizeInPoints.height * m_fContentScaleFactor);
            setGLDefaultValues();

            if (m_fContentScaleFactor != 1)
            {
                updateContentScaleFactor();
            }

            CCTouchDispatcher pTouchDispatcher = CCTouchDispatcher.sharedDispatcher();

            CCApplication.sharedApplication().TouchDelegate = pTouchDispatcher;
            pTouchDispatcher.IsDispatchEvents = true;
        }
        public void drawNumberOfQuads(int n, int start)
        {
            if (n == start)
            {
                return;
            }
            if (this.m_pQuads == null || (int)this.m_pQuads.Length < 1)
            {
                return;
            }
            CCApplication texture2D = CCApplication.sharedApplication();

            CCDirector.sharedDirector().getWinSize();
            texture2D.basicEffect.Texture            = this.Texture.getTexture2D();
            texture2D.basicEffect.TextureEnabled     = true;
            texture2D.GraphicsDevice.BlendState      = BlendState.AlphaBlend;
            texture2D.basicEffect.VertexColorEnabled = true;
            List <VertexPositionColorTexture> vertexPositionColorTextures = new List <VertexPositionColorTexture>();

            short[] numArray = new short[n * 6];
            for (int i = start; i < start + n; i++)
            {
                ccV3F_C4B_T2F_Quad mPQuads = this.m_pQuads[i];
                if (mPQuads != null)
                {
                    vertexPositionColorTextures.AddRange(mPQuads.getVertices(ccDirectorProjection.kCCDirectorProjection3D).ToList <VertexPositionColorTexture>());
                    numArray[i * 6]     = (short)(i * 4);
                    numArray[i * 6 + 1] = (short)(i * 4 + 1);
                    numArray[i * 6 + 2] = (short)(i * 4 + 2);
                    numArray[i * 6 + 3] = (short)(i * 4 + 2);
                    numArray[i * 6 + 4] = (short)(i * 4 + 1);
                    numArray[i * 6 + 5] = (short)(i * 4 + 3);
                }
            }
            VertexElement[]   vertexElement     = new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Color, 0), new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) };
            VertexDeclaration vertexDeclaration = new VertexDeclaration(vertexElement);

            foreach (EffectPass pass in texture2D.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                texture2D.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, vertexPositionColorTextures.ToArray(), 0, vertexPositionColorTextures.Count, numArray, 0, vertexPositionColorTextures.Count / 2);
            }
        }
Exemple #19
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            // 设置全屏
            graphics.IsFullScreen = true;

            Content.RootDirectory = "Content";

            // Windows Phone 的默认帧速率为 30 fps。
            TargetElapsedTime = TimeSpan.FromTicks(333333);

            // 延长锁定时的电池寿命。
            InactiveSleepTime = TimeSpan.FromSeconds(1);

            application = new AppDelegate(this, graphics);

            this.Components.Add(application);
        }
Exemple #20
0
        public override void draw()
        {
            base.draw();
            CCApplication mCOpacity = CCApplication.sharedApplication();

            CCDirector.sharedDirector().getWinSize();
            mCOpacity.basicEffect.VertexColorEnabled = true;
            mCOpacity.basicEffect.TextureEnabled     = false;
            mCOpacity.basicEffect.Alpha = (float)this.m_cOpacity / 255f;
            VertexElement[]   vertexElement     = new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector4, VertexElementUsage.Color, 0) };
            VertexDeclaration vertexDeclaration = new VertexDeclaration(vertexElement);

            foreach (EffectPass pass in mCOpacity.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                mCOpacity.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleStrip, this.vertices, 0, 2);
            }
            mCOpacity.basicEffect.Alpha = 1f;
        }
Exemple #21
0
        /// <summary>
        /// Pops out a scene from the queue.
        /// This scene will replace the running one.
        /// The running scene will be deleted. If there are no more scenes in the stack the execution is terminated.
        /// ONLY call it if there is a running scene.
        /// </summary>
        public void popScene()
        {
            Debug.Assert(m_pRunningScene != null, "m_pRunningScene cannot be null");

            if (m_pobScenesStack.Count > 0)
            {
                m_pobScenesStack.RemoveAt(m_pobScenesStack.Count - 1);
            }
            int c = m_pobScenesStack.Count;

            if (c == 0)
            {
                CCApplication.sharedApplication().Game.Exit();
                end();
            }
            else
            {
                m_bSendCleanupToScene = true;
                m_pNextScene          = m_pobScenesStack[c - 1];
            }
        }
Exemple #22
0
        protected void showFPS()
        {
            CCDirector mUFrames = this;

            mUFrames.m_uFrames = mUFrames.m_uFrames + 1;
            CCDirector mFAccumDt = this;

            mFAccumDt.m_fAccumDt = mFAccumDt.m_fAccumDt + this.m_fDeltaTime;
            if (this.m_fAccumDt > ccMacros.CC_DIRECTOR_FPS_INTERVAL)
            {
                this.m_fFrameRate = (float)((float)this.m_uFrames) / this.m_fAccumDt;
                this.m_uFrames    = 0;
                this.m_fAccumDt   = 0f;
                this.m_pszFPS     = string.Format("{0}", this.m_fFrameRate);
            }
            SpriteFont spriteFont = CCApplication.sharedApplication().content.Load <SpriteFont>("fonts/Arial");

            CCApplication.sharedApplication().spriteBatch.Begin();
            CCApplication.sharedApplication().spriteBatch.DrawString(spriteFont, this.m_pszFPS, new Vector2(0f, CCApplication.sharedApplication().getSize().height - 50f), new Color(0, 255, 255));
            CCApplication.sharedApplication().spriteBatch.End();
        }
Exemple #23
0
        public override void draw()
        {
            base.draw();
            if (m_uNuPoints <= 1)
            {
                return;
            }

            CCApplication app        = CCApplication.sharedApplication();
            float         startAlpha = app.basicEffect.Alpha;
            CCSize        size       = CCDirector.sharedDirector().getWinSize();

            app.basicEffect.VertexColorEnabled = true;
            app.basicEffect.TextureEnabled     = true;
            app.basicEffect.Alpha   = (float)Opacity / 255.0f;
            app.basicEffect.Texture = Texture.Texture;

            /*
             *  ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex );
             *  ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
             *
             *  ccGLBindTexture2D( m_pTexture->getName() );
             *
             *  glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, m_pVertices);
             *  glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_pTexCoords);
             *  glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, m_pColorPointer);
             *
             *  glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)m_uNuPoints*2);
             */

            // SEE CCDrawingPrimitives.cs line 275


            foreach (var pass in app.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                app.GraphicsDevice.DrawUserPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleStrip, m_pVerticesPCT, 0, m_uNuPoints * 2);
            }
            app.basicEffect.Alpha = startAlpha;
        }
Exemple #24
0
        protected bool initWithItems(params CCMenuItem[] item)
        {
            CCRect cCRect;

            if (!base.init())
            {
                return(false);
            }
            this.m_bIsTouchEnabled = true;
            CCSize winSize = CCDirector.sharedDirector().getWinSize();

            this.m_bIsRelativeAnchorPoint = false;
            this.anchorPoint = new CCPoint(0.5f, 0.5f);
            this.contentSize = winSize;
            CCApplication.sharedApplication().statusBarFrame(out cCRect);
            ccDeviceOrientation _ccDeviceOrientation = CCDirector.sharedDirector().deviceOrientation;

            if (_ccDeviceOrientation == ccDeviceOrientation.kCCDeviceOrientationLandscapeLeft || _ccDeviceOrientation == ccDeviceOrientation.kCCDeviceOrientationLandscapeRight)
            {
                CCSize cCSize = winSize;
                cCSize.height = cCSize.height - cCRect.size.width;
            }
            else
            {
                CCSize cCSize1 = winSize;
                cCSize1.height = cCSize1.height - cCRect.size.height;
            }
            this.position = new CCPoint(winSize.width / 2f, winSize.height / 2f);
            if (item != null)
            {
                CCMenuItem[] cCMenuItemArray = item;
                for (int i = 0; i < (int)cCMenuItemArray.Length; i++)
                {
                    this.addChild(cCMenuItemArray[i]);
                }
            }
            this.m_pSelectedItem = null;
            this.m_eState        = tCCMenuState.kCCMenuStateWaiting;
            return(true);
        }
        /// <summary>
        /// draws a circle given the center, radius and number of segments.
        /// </summary>
        public static void ccDrawCircle(CCPoint center, float radius, float angle, int segments, bool drawLineToCenter, ccColor4B color)
        {
            int additionalSegment = 1;

            if (drawLineToCenter)
            {
                ++additionalSegment;
            }

            CCApplication app    = CCApplication.sharedApplication();
            float         factor = CCDirector.sharedDirector().ContentScaleFactor;
            float         coef   = 2.0f * (float)(Math.PI) / segments;

            VertexPositionColor[] vertices = new VertexPositionColor[2 * (segments + 2)]; //	float *vertices = (float *)malloc( sizeof(float)*2*(segs+2));

            //memset(vertices, 0, sizeof(float) * 2 * (segs + 2));

            for (int i = 0; i <= segments; i++)
            {
                float rads = i * coef;
                float j    = radius * (float)Math.Cos(rads + angle) + center.x;
                float k    = radius * (float)Math.Sin(rads + angle) + center.y;

                vertices[i]          = new VertexPositionColor();
                vertices[i].Position = new Vector3(j * factor, k * factor, 0);
                vertices[i].Color    = new Color(color.r, color.g, color.b, color.a);
            }

            //vertices[(segments + 1) * 2] = new VertexPositionColor();
            //vertices[(segments + 1) * 2].Position = new Vector3(center.x * factor, center.y * factor, 0);

            app.basicEffect.TextureEnabled     = false;
            app.basicEffect.VertexColorEnabled = true;
            foreach (var pass in app.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, segments);
            }
        }
Exemple #26
0
        public override void draw()
        {
            base.draw();
            if (this.m_uNuPoints <= 1)
            {
                return;
            }
            CCApplication opacity = CCApplication.sharedApplication();
            float         alpha   = opacity.basicEffect.Alpha;

            CCDirector.sharedDirector().getWinSize();
            opacity.basicEffect.VertexColorEnabled = true;
            opacity.basicEffect.TextureEnabled     = true;
            opacity.basicEffect.Alpha   = (float)this.Opacity / 255f;
            opacity.basicEffect.Texture = this.Texture.Texture;
            foreach (EffectPass pass in opacity.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                opacity.GraphicsDevice.DrawUserPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleStrip, this.m_pVerticesPCT, 0, this.m_uNuPoints * 2);
            }
            opacity.basicEffect.Alpha = alpha;
        }
Exemple #27
0
        public CCTexture2D addImage(string fileimage)
        {
            CCTexture2D textured;

            lock (this.m_pDictLock)
            {
                string key = fileimage;
                if (this.m_pTextures.TryGetValue(key, out textured))
                {
                    return(textured);
                }
                Texture2D texture = CCApplication.sharedApplication().content.Load <Texture2D>(fileimage);
                textured = new CCTexture2D();
                if (textured.initWithTexture(texture))
                {
                    this.m_pTextures.Add(key, textured);
                    return(textured);
                }
                return(null);
            }
            return(textured);
        }
Exemple #28
0
        /** shows the FPS in the screen */
        protected void showFPS()
        {
            m_uFrames++;
            m_fAccumDt += m_fDeltaTime;

            if (m_fAccumDt > ccMacros.CC_DIRECTOR_FPS_INTERVAL)
            {
                m_fFrameRate = m_uFrames / m_fAccumDt;
                m_uFrames    = 0;
                m_fAccumDt   = 0;

                m_pszFPS = string.Format("{0}", m_fFrameRate);
            }

            SpriteFont font = CCApplication.sharedApplication().content.Load <SpriteFont>(@"fonts/Arial");

            CCApplication.sharedApplication().spriteBatch.Begin();
            CCApplication.sharedApplication().spriteBatch.DrawString(font,
                                                                     m_pszFPS,
                                                                     new Vector2(0, CCApplication.sharedApplication().getSize().height - 50),
                                                                     new Color(0, 255, 255));
            CCApplication.sharedApplication().spriteBatch.End();
        }
Exemple #29
0
        /// <summary>
        /// override visit
        //  don't call visit on it's children
        /// </summary>
        public override void visit()
        {
            // CAREFUL:
            // This visit is almost identical to CocosNode#visit
            // with the exception that it doesn't call visit on it's children
            //
            // The alternative is to have a void CCSprite#visit, but
            // although this is less mantainable, is faster
            //
            if (!m_bIsVisible)
            {
                return;
            }

            //glPushMatrix();

            //if (m_pGrid && m_pGrid->isActive())
            //{
            //    m_pGrid->beforeDraw();
            //    transformAncestors();
            //}

            transform();

            draw();

            //if (m_pGrid && m_pGrid->isActive())
            //{
            //    m_pGrid->afterDraw(this);
            //}

            CCApplication.sharedApplication().basicEffect.World = CCApplication.sharedApplication().basicEffect.World *Matrix.Invert(m_tCCNodeTransform);
            m_tCCNodeTransform = Matrix.Identity;

            //glPopMatrix();
        }
Exemple #30
0
 public static string getFileData(string pszFileName, string pszMode, ulong pSize)
 {
     return(CCApplication.sharedApplication().content.Load <CCContent>(pszFileName).Content);
 }
Exemple #31
0
        public override void Initialize()
        {
            //DebugSystem.Initialize(Game, "fonts/debugfont");
            //DebugSystem.Instance.FpsCounter.Visible = true;
            //DebugSystem.Instance.TimeRuler.Visible = true;
            //DebugSystem.Instance.TimeRuler.ShowLog = true;

            s_pSharedApplication = this;

            InitInstance();

            base.Initialize();
        }
 public void end()
 {
     CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(null);
 }
        public override void Initialize()
        {
            sm_pSharedApplication = this;

            PVRFrameEnableControlWindow(false);

            initInstance();

            base.Initialize();
        }