I already looked at http://msdn.microsoft.com/en-us/library/bb196414.aspx#ID2EEF here they explain how to draw 2D lines in xna, but i get an exeption(see script)
{
int points = 3;//I tried different values(1,2,3,4)
VertexPositionColor[] primitiveList = new VertexPositionColor[points];
for (int x = 0; x < points / 2; x++)
{
for (int y = 0; y < 2; y++)
{
primitiveList[(x * 2) + y] = new VertexPositionColor(
new Vector3(x * 100, y * 100, 0), Color.White);
}
}
// Initialize an array of indices of type short.
short[] lineListIndices = new short[(points * 2) - 2];
// Populate the array with references to indices in the vertex buffer
for (int i = 0; i < points - 1; i++)
{
lineListIndices[i * 2] = (short)(i);
lineListIndices[(i * 2) + 1] = (short)(i + 1);
}
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
PrimitiveType.LineList,
primitiveList,
0, // vertex buffer offset to add to each element of the index buffer
8, // number of vertices in pointList
lineListIndices, // the index buffer
0, // first index element to read
7 // number of primitives to draw
); <---This parameter must be a valid index within the array. Parameter name: primitiveCount
}
but i have no idea on how to fix this, since this is my first time making 2d graphics using 3d rendering
Background:
im making an 2d game engine for xna, and i want to make a class for drawing simple figures, i already know you can use a 1x1 Texture2D pixel trick for drawing, but i want to know this way as well, because else the CPU will be doing all of the calculations while the GPU can easily handle this.