我已經看了看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