コード例 #1
0
ファイル: SceneManager.cs プロジェクト: fjpavm/gdddev
        /// <summary>
        /// The draw.
        /// </summary>
        /// <param name="gameTime">
        /// The gameTime.
        /// </param>
        public static void Draw(GameTime gameTime)
        {
            // draw this in the correct order so the scenes behind the topmost scene get drawn behind the topmost scene
            foreach (Scene scene in GetVisibleScenes())
            {
                if (scene.TopMost)
                {
                    game.GraphicsDevice.RenderState.AlphaBlendEnable = true;
                    game.GraphicsDevice.RenderState.SourceBlend      = Blend.BothSourceAlpha;
                    game.GraphicsDevice.RenderState.DestinationBlend = Blend.DestinationColor;

                    ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.OVERLAY);
                    ShaderManager.GetCurrentEffectGraphicsDevice().VertexDeclaration = vd;
                    ShaderManager.SetCurrentTechnique("Overlay");
                    ShaderManager.Begin();

                    foreach (EffectPass pass in ShaderManager.GetEffectPasses())
                    {
                        pass.Begin();
                        ShaderManager.GetCurrentEffectGraphicsDevice().Vertices[0].SetSource(
                            vb, 0, VertexPositionColor.SizeInBytes);
                        ShaderManager.GetCurrentEffectGraphicsDevice().DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                        pass.End();
                    }

                    ShaderManager.End();

                    game.GraphicsDevice.RenderState.AlphaBlendEnable = false;
                }

                scene.Draw(gameTime);
            }
        }
コード例 #2
0
        /// <summary>
        /// The draw physics vertices.
        /// </summary>
        public virtual void DrawPhysicsVertices()
        {
            if (Globals.displayState == DISPLAY_STATE.BOTH || Globals.displayState == DISPLAY_STATE.TWO_DIM)
            {
                // draw the 2d representation of the model
                ShaderManager.AddEffect(ShaderManager.EFFECT_ID.SIMPLE, "SimpleEffect", this.Game);

                VertexPositionColor[] verticesPC;

                verticesPC = new VertexPositionColor[this.PhysicsGeometry.WorldVertices.Count + 1];
                for (int i = 0; i < this.PhysicsGeometry.WorldVertices.Count; i++)
                {
                    verticesPC[i] =
                        new VertexPositionColor(
                            new Vector3(this.PhysicsGeometry.WorldVertices[i], SceneManager.Z_POSITION), Color.Green);
                }

                verticesPC[this.PhysicsGeometry.WorldVertices.Count] =
                    new VertexPositionColor(
                        new Vector3(this.PhysicsGeometry.WorldVertices[0], SceneManager.Z_POSITION), Color.Green);

                var vd = new VertexDeclaration(this.Game.GraphicsDevice, VertexPositionColor.VertexElements);
                var VB = new VertexBuffer(
                    this.Game.GraphicsDevice,
                    VertexPositionColor.SizeInBytes * (this.PhysicsGeometry.WorldVertices.Count + 1),
                    BufferUsage.None);
                VB.SetData(verticesPC);

                ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.SIMPLE);

                ShaderManager.SetValue("WVP", this.scene.Camera.View * this.scene.Camera.Perspective);

                ShaderManager.SetValue("Color", Color.Black.ToVector4());

                ShaderManager.SetCurrentTechnique("SimpleTechnique");
                ShaderManager.GetCurrentEffectGraphicsDevice().VertexDeclaration = vd;
                ShaderManager.Begin();
                foreach (EffectPass pass in ShaderManager.GetEffectPasses())
                {
                    pass.Begin();
                    ShaderManager.GetCurrentEffectGraphicsDevice().Vertices[0].SetSource(
                        VB, 0, VertexPositionColor.SizeInBytes);
                    ShaderManager.GetCurrentEffectGraphicsDevice().DrawPrimitives(
                        PrimitiveType.LineStrip, 0, this.PhysicsGeometry.WorldVertices.Count);
                    pass.End();
                }

                ShaderManager.End();
            }
        }