Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The draw.
        /// </summary>
        /// <param name="gameTime">
        /// The game time.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        public override void Draw(GameTime gameTime)
        {
            if (this.HeaderText == null)
            {
                throw new ArgumentNullException("HeaderText should not be null");
            }

            if (this.BodyText == null)
            {
                throw new ArgumentNullException("BodyText should not be null");
            }

            if (this.TextBoxSize == null)
            {
                throw new ArgumentNullException("TextBoxSize should not be null");
            }

            // draw the texture
            ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.TEXTURE);

            ShaderManager.SetValue("World", Matrix.CreateTranslation(this.Position3D));
            ShaderManager.SetValue("View", this.scene.Camera.View);
            ShaderManager.SetValue("Projection", this.scene.Camera.Perspective);

            ShaderManager.SetValue("tex", this.TextTexture);

            ShaderManager.CommitChanges();

            ShaderManager.Begin();
            ShaderManager.GetCurrentEffect().Techniques["TextureTechnique"].Passes[0].Begin();

            this.GraphicsDevice.VertexDeclaration = TextureSpriteVertexDeclaration;
            this.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, this.textSprite, 0, 2);

            ShaderManager.GetCurrentEffect().Techniques["TextureTechnique"].Passes[0].End();

            ShaderManager.End();
            this.DrawPhysicsVertices();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The draw.
        /// </summary>
        public void Draw()
        {
            if (this.Backgrounds == null || this.Backgrounds.Length == 0)
            {
                return;
            }

            var spriteBatch = (SpriteBatch)this.scene.Game.Services.GetService(typeof(SpriteBatch));

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);

            // using a pixelshader with spritebatch - http://msdn.microsoft.com/en-us/library/bb313868.aspx
            ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.BACKGROUND);

            ShaderManager.Begin();
            ShaderManager.GetCurrentEffect().CurrentTechnique.Passes[0].Begin();

            var p = new Plane(-Vector3.UnitZ, -10.0f);

            foreach (BackgroundLayer backgroundLayer in this.Backgrounds)
            {
                if (backgroundLayer.Image == null)
                {
                    continue;
                }

                Ray     leftRay = this.scene.Camera.Unproject(0, this.scene.Game.GraphicsDevice.Viewport.Height / 2);
                Vector3?left3D  = leftRay.IntersectsAt(p);
                float   left    = left3D.HasValue ? left3D.Value.X : this.min;

                Ray rightRay = this.scene.Camera.Unproject(
                    this.scene.Game.GraphicsDevice.Viewport.Width - 1, this.scene.Game.GraphicsDevice.Viewport.Height / 2);
                Vector3?right3D = rightRay.IntersectsAt(p);
                float   right   = right3D.HasValue ? right3D.Value.X : this.max;

                float offset = -((Hero.GetHeroPosition().X - this.min) * backgroundLayer.ScrollSpeed * 0.02f) %
                               backgroundLayer.Image.Width;

                float imgWidth   = backgroundLayer.Image.Width * backgroundLayer.WidthBias;
                float screenLeft = this.min - backgroundLayer.Image.Width;
                int   num        = (int)((left - screenLeft) / imgWidth);
                left = screenLeft + (num * imgWidth);
                num  = (int)(((right - left - offset) / imgWidth) + 2);

                int?prevRightX = null;
                for (int i = 0; i < num; i++)
                {
                    float     imgLeft  = left + offset + i * imgWidth;
                    float     imgRight = imgLeft + imgWidth;
                    var       scrLeft  = this.scene.Camera.Project(new Vector3(imgLeft, 0, -10));
                    var       scrRight = this.scene.Camera.Project(new Vector3(imgRight, 0, -10));
                    Rectangle destRect = new Rectangle(
                        prevRightX ?? (int)scrLeft.X,
                        0,
                        (int)(scrRight.X - scrLeft.X),
                        this.scene.Game.GraphicsDevice.Viewport.Height - 1);
                    spriteBatch.Draw(backgroundLayer.Image, destRect, Color.White);
                    prevRightX = destRect.X + destRect.Width - 1;
                }
            }

            spriteBatch.End();
            ShaderManager.GetCurrentEffect().CurrentTechnique.Passes[0].End();
            ShaderManager.End();
        }