QuadRenderer.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Xna.Framework;
  4. using Microsoft.Xna.Framework.Graphics;
  5. namespace Samples.Deferred
  6. {
  7. public partial class QuadRenderComponent
  8. {
  9. GraphicsDevice graphicsDevice;
  10. VertexPositionTexture[] verts = null;
  11. short[] ib = null;
  12. public QuadRenderComponent(GraphicsDevice graphicsDevice)
  13. {
  14. this.graphicsDevice = graphicsDevice;
  15. verts = new VertexPositionTexture[]
  16. {
  17. new VertexPositionTexture(
  18. new Vector3(0,0,0),
  19. new Vector2(1,1)),
  20. new VertexPositionTexture(
  21. new Vector3(0,0,0),
  22. new Vector2(0,1)),
  23. new VertexPositionTexture(
  24. new Vector3(0,0,0),
  25. new Vector2(0,0)),
  26. new VertexPositionTexture(
  27. new Vector3(0,0,0),
  28. new Vector2(1,0))
  29. };
  30. ib = new short[] { 0, 1, 2, 2, 3, 0 };
  31. return;
  32. }
  33. public void Render(Vector2 v1, Vector2 v2)
  34. {
  35. graphicsDevice.BlendState = BlendState.Opaque;
  36. verts[0].Position.X = v2.X;
  37. verts[0].Position.Y = v1.Y;
  38. verts[1].Position.X = v1.X;
  39. verts[1].Position.Y = v1.Y;
  40. verts[2].Position.X = v1.X;
  41. verts[2].Position.Y = v2.Y;
  42. verts[3].Position.X = v2.X;
  43. verts[3].Position.Y = v2.Y;
  44. graphicsDevice.DrawUserIndexedPrimitives<VertexPositionTexture>
  45. (PrimitiveType.TriangleList, verts, 0, 4, ib, 0, 2);
  46. }
  47. }
  48. }