#region Using Statements using System; using System.Collections.Generic; 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.Storage; #endregion namespace BlogExample01 { public class BlogExample : Microsoft.Xna.Framework.Game { GraphicsDeviceManager m_graphics; ContentManager m_content; GraphicsDevice m_device; private Effect m_effect; private VertexPositionColor[] m_vertices; private VertexDeclaration m_vd; private Matrix m_matView; private Matrix m_matProj; private Matrix m_matWorld; public BlogExample() { m_graphics = new GraphicsDeviceManager(this); m_content = new ContentManager(Services); } protected override void Initialize() { base.Initialize(); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { m_device = m_graphics.GraphicsDevice; m_effect = m_content.Load("simpleshader"); m_vertices = new VertexPositionColor[3]; m_vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f); m_vertices[0].Color = Color.Red; m_vertices[1].Position = new Vector3(0, 0.5f, 0f); m_vertices[1].Color = Color.Green; m_vertices[2].Position = new Vector3(0.5f, -0.5f, 0f); m_vertices[2].Color = Color.Yellow; m_vd = new VertexDeclaration(m_device, VertexPositionColor.VertexElements); m_matView = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 2.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f)); m_matProj = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, (float)m_device.Viewport.Width / (float)m_device.Viewport.Height, 1.0f, 100.0f); m_matWorld = Matrix.Identity; } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { m_content.Unload(); } } protected override void Update(GameTime gameTime) { base.Update(gameTime); } protected override void Draw(GameTime gameTime) { m_graphics.GraphicsDevice.Clear(Color.CornflowerBlue); m_device.RenderState.CullMode = CullMode.None; m_device.RenderState.FillMode = FillMode.Solid; m_effect.CurrentTechnique = m_effect.Techniques["Simplest"]; m_effect.Parameters["xViewProjection"].SetValue(m_matView * m_matProj * m_matWorld); m_effect.Begin(); foreach (EffectPass pass in m_effect.CurrentTechnique.Passes) { pass.Begin(); m_device.VertexDeclaration = m_vd; m_device.DrawUserPrimitives(PrimitiveType.TriangleList, m_vertices, 0, 1); pass.End(); } m_effect.End(); base.Draw(gameTime); } } }