我已经看了看http://msdn.microsoft.com/en-us/library/bb196414.aspx#ID2EEF 在这里,他们解释了如何利用XNA 2D线,但我得到一个exeption(见脚本)XNA - 绘制二维线
{
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
}
,但我对如何解决不知道这一点,因为这是我第一次使用3D渲染制作2D图形
背景:
IM做了XNA的2D游戏引擎,我想使一个类绘制简单的数字, 我已经知道你可以使用1x1用于绘制的Texture2D像素技巧,但我也想知道这种方式,因为否则CPU将执行所有计算,而GPU可以轻松处理此问题。
我使用Google本图书馆https://bitbucket.org/C3/2d-xna-primitives/wiki/Home – Dmi7ry