private void DrawGame() { GraphicsDevice.SetRenderTarget(_mainTarget); GraphicsDevice.Clear(Color.Black); _map.Draw(_spriteBatch, _mapsTex, _mapBackTex, 0, 2); _particleManager.DrawParticles(_spritesTex, true); for (var i = 0; i < _characters.Length; i++) { if (_characters[i] != null) { _characters[i].Draw(_spriteBatch); } } _particleManager.DrawParticles(_spritesTex, false); _map.Draw(_spriteBatch, _mapsTex, _mapBackTex, 2, 3); GraphicsDevice.SetRenderTarget(null); _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque); _spriteBatch.Draw(_mainTarget, Vector2.Zero, Color.White); _spriteBatch.End(); if (QuakeManager.Blast.Value > 0) { _spriteBatch.Begin(); for (var i = 0; i < 5; i++) { _spriteBatch.Draw( _mainTarget, QuakeManager.Blast.Center - Scroll, new Rectangle(0, 0, (int)ScreenSize.X, (int)ScreenSize.Y), new Color(new Vector4(1f, 1f, 1f, 0.35f * (QuakeManager.Blast.Value / QuakeManager.Blast.Magnitude))), 0f, QuakeManager.Blast.Center - Scroll, (1 + (QuakeManager.Blast.Magnitude - QuakeManager.Blast.Value) * 0.1f + ((i + 1) / 40f)), SpriteEffects.None, 1f ); } _spriteBatch.End(); } }
protected override void Draw(GameTime gameTime) { GraphicsDevice.SetRenderTarget(Canvas); GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone); if (Convert.ToBoolean(ConfigManager.GetValue("enable_sky"))) { sky.Draw(spriteBatch); } SceneManager.DrawScenes(spriteBatch); ParticleManager.DrawParticles(spriteBatch); spriteBatch.End(); GraphicsDevice.SetRenderTarget(null); GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone); spriteBatch.Draw(Canvas, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, CanvasScale, SpriteEffects.None, 0f); spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// We'll draw our standard stuff--map, particles, characters, /// and more particles, then do a bunch of post effects. /// /// The post effects are covered in chapter 11. /// </summary> private void DrawGame() { //graphics.GraphicsDevice.SetRenderTarget(0, mainTarget); graphics.GraphicsDevice.SetRenderTarget(mainTarget); graphics.GraphicsDevice.Clear(Color.Black); map.Draw(spriteBatch, mapsTex, mapBackTex, 0, 2); pManager.DrawParticles(spritesTex, true); for (int i = 0; i < character.Length; i++) { if (character[i] != null) { character[i].Draw(spriteBatch); } } pManager.DrawParticles(spritesTex, false); /* * Draw our refract particles to the refractTarget. */ //graphics.GraphicsDevice.SetRenderTarget(0, refractTarget); graphics.GraphicsDevice.SetRenderTarget(refractTarget); graphics.GraphicsDevice.Clear(Color.Black); pManager.DrawRefractParticles(spritesTex); /* * Set up our water texture. */ EffectPass pass; float waterLevel = map.water - (.2f * ScreenSize.Y); if (map.water > 0f) { //graphics.GraphicsDevice.SetRenderTarget(0, waterTarget); graphics.GraphicsDevice.SetRenderTarget(waterTarget); float wLev = (ScreenSize.Y / 2f + waterLevel - Scroll.Y) / ScreenSize.Y; waterEffect.Parameters["delta"].SetValue(waterDelta); waterEffect.Parameters["theta"].SetValue(waterTheta); waterEffect.Parameters["horizon"].SetValue(wLev); //waterEffect.Begin(); waterEffect.CurrentTechnique.Passes[0].Apply(); //spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.None, spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);//, //SaveStateMode.SaveState); pass = waterEffect.CurrentTechnique.Passes[0]; //pass.Begin(); //spriteBatch.Draw(mainTarget.GetTexture(), new Rectangle(0, 0, 256, 256), Color.White); spriteBatch.Draw(mainTarget, new Rectangle(0, 0, 256, 256), Color.White); //pass.End(); spriteBatch.End(); //waterEffect.End(); } /* * Switch to gameTarget and draw our mainTarget with refraction and * color filter effects as well as water and bloom overlay. */ //graphics.GraphicsDevice.SetRenderTarget(0, gameTarget); graphics.GraphicsDevice.SetRenderTarget(gameTarget); if (gameMode == GameModes.Menu) { //pauseEffect.Begin(); pauseEffect.CurrentTechnique.Passes[0].Apply(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque); //.None, //SaveStateMode.SaveState); pass = pauseEffect.CurrentTechnique.Passes[0]; //pass.Begin(); //spriteBatch.Draw(mainTarget.GetTexture(), new Vector2(), Color.White); spriteBatch.Draw(mainTarget, new Vector2(), Color.White); //pass.End(); spriteBatch.End(); //pauseEffect.End(); } else { //graphics.GraphicsDevice.Textures[1] = refractTarget.GetTexture(); graphics.GraphicsDevice.Textures[1] = refractTarget; filterEffect.Parameters["burn"].SetValue(.15f); filterEffect.Parameters["saturation"].SetValue(0.5f); filterEffect.Parameters["r"].SetValue(1.0f); filterEffect.Parameters["g"].SetValue(0.98f); filterEffect.Parameters["b"].SetValue(0.85f); filterEffect.Parameters["brite"].SetValue(0.05f); //filterEffect.Begin(); filterEffect.CurrentTechnique.Passes[0].Apply(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque); //.None, //SaveStateMode.SaveState); pass = filterEffect.CurrentTechnique.Passes[0]; //pass.Begin(); //spriteBatch.Draw(mainTarget.GetTexture(), new Vector2(), Color.White); spriteBatch.Draw(mainTarget, new Vector2(), Color.White); //pass.End(); spriteBatch.End(); //filterEffect.End(); graphics.GraphicsDevice.Textures[1] = null; //if (map.water > 0f) if (false) { spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); //spriteBatch.Draw(waterTarget.GetTexture(), new Rectangle(0, spriteBatch.Draw(waterTarget, new Rectangle(0, (int)(waterLevel - Scroll.Y), (int)ScreenSize.X, (int)ScreenSize.Y), Color.White); spriteBatch.End(); } map.Draw(spriteBatch, mapsTex, mapBackTex, 2, 3); //if (hasBloom) if (false) { //spriteBatch.Begin(SpriteBlendMode.Additive); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.Additive); for (int i = 0; i < 2; i++) { //spriteBatch.Draw(bloomTarget[i].GetTexture(), spriteBatch.Draw(bloomTarget[i], new Rectangle(0, 0, (int)ScreenSize.X, (int)ScreenSize.Y), Color.White); } spriteBatch.End(); } } /* * Set up the bloom surfaces with our current scene. Since we're * using an already-bloomed scene to create bloom, we end up with a * sort of feedback that gives us a nice haze effect. */ for (int i = 0; i < 2; i++) { hasBloom = true; //graphics.GraphicsDevice.SetRenderTarget(0, bloomTarget[i]); graphics.GraphicsDevice.SetRenderTarget(bloomTarget[i]); bloomEffect.Parameters["a"].SetValue(.25f); bloomEffect.Parameters["v"].SetValue((float)(i + 1) * 0.01f * ((float)Math.Cos((double)bloomPulse[i]) * .25f + 0.7f)); //bloomEffect.Begin(); bloomEffect.CurrentTechnique.Passes[0].Apply(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque); //.None, //SaveStateMode.SaveState); pass = bloomEffect.CurrentTechnique.Passes[0]; //pass.Begin(); //spriteBatch.Draw(gameTarget.GetTexture(), spriteBatch.Draw(gameTarget, new Rectangle(0, 0, 128 * (i + 1), 128 * (i + 1)), Color.White); //pass.End(); spriteBatch.End(); //bloomEffect.End(); } /* * Render back the gameTarget to backbuffer. */ //graphics.GraphicsDevice.SetRenderTarget(0, null); graphics.GraphicsDevice.SetRenderTarget(null); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.Opaque); //.None); //spriteBatch.Draw(gameTarget.GetTexture(), new Vector2(), Color.White); spriteBatch.Draw(gameTarget, new Vector2(), Color.White); spriteBatch.End(); /* * Draw our blast effect, which we set up in chapter 8. */ spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); if (QuakeManager.Blast.Value > 0f) { for (int i = 7; i >= 0; i--) { //spriteBatch.Draw(gameTarget.GetTexture(), spriteBatch.Draw(gameTarget, QuakeManager.Blast.center - Scroll, new Rectangle(0, 0, (int)ScreenSize.X, (int)ScreenSize.Y), new Color(new Vector4(1f, 1f, 1f, .25f * (QuakeManager.Blast.Value / QuakeManager.Blast.Magnitude))), 0f, QuakeManager.Blast.center - Scroll, (1.0f + (QuakeManager.Blast.Magnitude - QuakeManager.Blast.Value) * .1f + ((float)(i) / 50f)), SpriteEffects.None, 1f); } } spriteBatch.End(); }