/// <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(); }
/// <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(); }
private static Texture2D RenderToTarget(Model model, ModelAnimationPlayer player, Microsoft.Xna.Framework.Game game, Matrix world, out Texture2D Sillouette) { DepthStencilBuffer old = ShadowMapManager.SetupShadowMap(game.GraphicsDevice, ref renderTarget, ref depthBuffer); BoundingSphere bs = new BoundingSphere(); bool first = true; foreach (ModelMesh mesh in model.Meshes) { if (first) { bs = mesh.BoundingSphere; first = false; } else { bs = BoundingSphere.CreateMerged(bs, mesh.BoundingSphere); } } bs.Center.X = bs.Center.Z; bs.Radius *= 1.5f; ShaderManager.AddEffect(ShaderManager.EFFECT_ID.PHYSICS, "PhysicsRenderer", game); ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.PHYSICS); ShaderManager.SetValue("World", world); Matrix m = Matrix.Identity; m.M33 = 0; m.M43 = 0.5f; ShaderManager.SetValue("Projection", m); Matrix view; view = Matrix.CreateTranslation(-bs.Center) * Matrix.CreateScale(1 / bs.Radius, 1 / bs.Radius, 1); ShaderManager.SetValue("Projection", m); ShaderManager.SetValue("View", view); ShaderManager.SetValue("usingBones", player != null); if (player != null) { ShaderManager.SetValue("Bones", player.GetSkinTransforms()); } ShaderManager.CommitChanges(); List <Effect> effects = new List <Effect>(); game.GraphicsDevice.Clear(Color.Black); foreach (ModelMesh mesh in model.Meshes) { effects.Clear(); foreach (ModelMeshPart part in mesh.MeshParts) { effects.Add(part.Effect); part.Effect = ShaderManager.GetCurrentEffect(); } mesh.Draw(); for (int i = 0; i < mesh.MeshParts.Count; i++) { mesh.MeshParts[i].Effect = effects[i]; } } ShadowMapManager.ResetGraphicsDevice(game.GraphicsDevice, old); Color[] textureColors = new Color[(int)(TextureSize.X * TextureSize.Y)]; renderTarget.GetTexture().GetData <Color>(textureColors); Sillouette = new Texture2D(game.GraphicsDevice, (int)TextureSize.X, (int)TextureSize.Y); Sillouette.SetData <Color>(textureColors); return(renderTarget.GetTexture()); }