Search code examples
c#xnaprimitive

XNA: DrawUserPrimitives - Drawing FILLED rectangles


I have a working line drawing code going using "DrawUserPrimitives" I have set up a function to "draw a rectangle" using a linestrip and VectorPositionColor

VertexPositionColor[] lineVertices = new VertexPositionColor[5];
lineVertices[0].Position = new Vector3(inMidPoint.X - halfWidth, inMidPoint.Y - halfLength, 0);
lineVertices[0].Color = inLineColor;

etc..

basicEffect.CurrentTechnique.Passes[0].Apply();
mGraphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, lineVertices, 0, lineVertices.Length - 1);

Using this method I can create the colored outline of a rectangle. Now, how can I fill in that rectangle with a color, using this system?


Solution

  • Use TriangleStrip instead of LineStrip - http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.primitivetype.aspx