| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace ShaderTest
- {
- public class ShaderTestGame : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- KeyboardState PreviousKeyState;
- KeyboardState CurrentKeyState;
- Texture2D background;
- Texture2D surge;
- SpriteFont font;
- List<Effect> shaderEffects;
- int shaderEffectIdx;
- public ShaderTestGame()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- shaderEffectIdx = 0;
- }
- protected override void Initialize()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- base.Initialize();
- }
- protected override void LoadContent()
- {
- font = Content.Load<SpriteFont>("font");
- background = Content.Load<Texture2D>(@"images\bg5");
- surge = Content.Load<Texture2D>(@"images\surge");
- shaderEffects = new List<Effect>();
- shaderEffects.Add(Content.Load<Effect>(@"effects\NoEffect"));
- shaderEffects.Add(Content.Load<Effect>(@"effects\HighContrast"));
- shaderEffects.Add(Content.Load<Effect>(@"effects\Bevels"));
- shaderEffects.Add(Content.Load<Effect>(@"effects\Grayscale"));
- shaderEffects.Add(Content.Load<Effect>(@"effects\ColorFlip"));
- shaderEffects.Add(Content.Load<Effect>(@"effects\Invert"));
- shaderEffects.Add(Content.Load<Effect>(@"effects\BlackOut"));
- shaderEffects.Add(Content.Load<Effect>(@"effects\RainbowH"));
- }
- protected override void Update(GameTime gameTime)
- {
- PreviousKeyState = CurrentKeyState;
- CurrentKeyState = Keyboard.GetState();
-
- if (CurrentKeyState.IsKeyDown(Keys.Escape)) this.Exit();
- if (CurrentKeyState.IsKeyDown(Keys.Up) && PreviousKeyState.IsKeyUp(Keys.Up))
- {
- shaderEffectIdx++;
- if (shaderEffectIdx >= shaderEffects.Count()) shaderEffectIdx = 0;
- }
- if (CurrentKeyState.IsKeyDown(Keys.Down) && PreviousKeyState.IsKeyUp(Keys.Down))
- {
- shaderEffectIdx--;
- if (shaderEffectIdx < 0 ) shaderEffectIdx = shaderEffects.Count() - 1;
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.Black);
- spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
- spriteBatch.Draw(background, new Vector2(-200, -200), Color.White);
- shaderEffects[shaderEffectIdx].CurrentTechnique.Passes[0].Apply();
- spriteBatch.Draw(surge, new Vector2(300,200), null, Color.White, 0f, Vector2.Zero, 2.0f, SpriteEffects.None, 0f);
- spriteBatch.End();
- spriteBatch.Begin();
- spriteBatch.DrawString(font, "Press Up/Down to change shader effect", new Vector2(10, 10), Color.White);
- spriteBatch.DrawString(font, "Current Effect: " + shaderEffects[shaderEffectIdx].Name, new Vector2(10, 30), Color.White);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
|