1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
4 using System.Collections.Generic;
9 static class GraphicsQuad
11 private static VertexBuffer vertexBuffer =
null;
12 private static IndexBuffer indexBuffer =
null;
13 private static BasicEffect basicEffect =
null;
14 private static GraphicsDevice graphicsDevice =
null;
16 public static void Init(GraphicsDevice graphics)
18 if (graphicsDevice !=
null) {
return; }
20 graphicsDevice = graphics;
22 vertexBuffer =
new VertexBuffer(graphics, VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly);
23 indexBuffer =
new IndexBuffer(graphics, IndexElementSize.SixteenBits, 4, BufferUsage.WriteOnly);
26 indexBuffer.SetData(
new ushort[] { 0, 1, 2, 3 });
28 basicEffect =
new BasicEffect(graphics) { TextureEnabled =
true };
30 GameMain.Instance.ResolutionChanged += () =>
36 private static void InitVertexData()
38 Vector2 halfPixelOffset = Vector2.Zero;
40 halfPixelOffset =
new Vector2(0.5f / GameMain.GraphicsWidth, 0.5f / GameMain.GraphicsHeight);
43 VertexPositionTexture[] vertices =
45 new VertexPositionTexture(
new Vector3(-1f, -1f, 1f),
new Vector2(0f, 1f) + halfPixelOffset),
46 new VertexPositionTexture(
new Vector3(-1f, 1f, 1f),
new Vector2(0f, 0f) + halfPixelOffset),
47 new VertexPositionTexture(
new Vector3(1f, -1f, 1f),
new Vector2(1f, 1f) + halfPixelOffset),
48 new VertexPositionTexture(
new Vector3(1f, 1f, 1f),
new Vector2(1f, 0f) + halfPixelOffset)
51 vertexBuffer.SetData(vertices);
54 public static void UseBasicEffect(Texture2D texture)
56 basicEffect.Texture = texture;
57 basicEffect.CurrentTechnique.Passes[0].Apply();
60 public static void Render()
62 graphicsDevice.SetVertexBuffer(vertexBuffer);
63 graphicsDevice.Indices = indexBuffer;
64 graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 2);