Advertisement
smc_gamer

QuadRenderer.cs

Feb 18th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Graphics;
  4.  
  5. namespace SMLimitless.Graphics
  6. {
  7.     internal sealed class QuadRenderer
  8.     {
  9.         // http://gamedev.stackexchange.com/questions/87150/rendering-a-fullscreen-quad-is-leaving-a-one-pixel-line-on-the-left-and-top
  10.  
  11.         private VertexPositionTexture[] triangles;
  12.         private short[] indexData = new short[] { 0, 1, 2, 2, 3, 0 };
  13.         private GraphicsDevice gfx;
  14.  
  15.         public QuadRenderer()
  16.         {
  17.             gfx = GameServices.Graphics;
  18.  
  19.             // texture coordinates semantic not used or needed
  20.             triangles = new VertexPositionTexture[]
  21.                          {
  22.                        new VertexPositionTexture(new Vector3(1, -1, 0),
  23.                                                  Vector2.Zero),
  24.                        new VertexPositionTexture(new Vector3(-1, -1, 0),
  25.                                                  Vector2.Zero),
  26.                        new VertexPositionTexture(new Vector3(-1, 1, 0),
  27.                                                  Vector2.Zero),
  28.                        new VertexPositionTexture(new Vector3(1, 1, 0),
  29.                                                  Vector2.Zero)
  30.                          };
  31.         }
  32.  
  33.         public void Render(Effect effect)
  34.         {
  35.             foreach (EffectPass p in effect.CurrentTechnique.Passes)
  36.                 p.Apply();
  37.  
  38.             Render();
  39.         }
  40.  
  41.         private void Render()
  42.         {
  43.             gfx.DrawUserIndexedPrimitives(PrimitiveType.TriangleList,
  44.                                                triangles, 0, 4,
  45.                                                indexData, 0, 2);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement