我正试图绕过头脑:
http://msdn.microsoft.com/en-us/library/bb196409.aspx
参考并不多。它简短,模糊,没有任何你可以学习的东西。
我想创建一个方法,该方法采用Triangle =(一个3个向量的类)列表,然后渲染它,然后能够用颜色或纹理填充它。
有人可以解释上述方法吗?因为我正在尝试的是不起作用。我试过添加一个三角形。我在下面的理解,请在我错的地方纠正我。
创建“一个三角形”时的方法:
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>
(
PrimitiveType.TriangleStrip,
"array of 3 VertexPositionColor?",
0,
(3? 9?),
"I have no clue what to put here and why I should put it here?",
"What do I put here?",
"If 1 triangle, value should be = 1? 1 Triangle = 1 Primitive"
);
我需要做些什么?根据我传递给我的方法的三角形数量,我是否渲染以及哪些值会根据有多少个三角形而改变?
...如果成功(希望有时候)我该如何填写呢?
请注意,没有模糊的简短答案,因为参考文献非常好。
答案 0 :(得分:5)
在我们开始之前,先澄清一下你的思维方式。在XNA中 - 您绘制线框(轮廓)三角形,或填充三角形或纹理三角形。没有任何礼物“现在画画”和“稍后填写”。你只能在帧缓冲区中已有的东西上绘制其他内容。
同样here是索引网格的背景。这是输入DrawUserIndexedPrimitives的数据(由顶点设置中的索引组成的顶点和三角形)。
鉴于此,这是绘制调用的工作原理
_effect.Texture = texture; // This sets the texture up so the
// shaders associated with this effect can access it
// The color in each vertex is modulated with the texture color
// and linearly interpolated across vertices
_effect.VertexColorEnabled = true;
foreach (var pass in _effect.CurrentTechnique.Passes)
{
pass.Apply(); // This sets up the shaders and their state
// TriangleList means that the indices are understood to be
// multiples of 3, where the 3 vertices pointed to are comprise
// one triangle
_device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList,
// The vertices. Note that there can be any number of vertices in here.
// What's important is the indices array (and the vertexOffset, primitivecount, vertexCount) that determine
// how many of the provided vertices will actually matter for this draw call
_vertices,
// The offset to the first vertex that the index 0 in the index array will refer to
// This is used to render a "part" of a bigger set of vertices, perhaps shared across
// different objects
0,
// The number of vertices to pick starting from vertexOffset. If the index array
// tried to index a vertex out of this range then the draw call will fail.
_vertices.Count,
// The indices (count = multiple of 3) that comprise separate triangle (because we said TriangleList -
// the rules are different depending on the primitive type)
_indices,
// Again, an offset inside the indices array so a part of a larger index array can be used
0,
// Number of indices. This HAS to be a multiple of 3 because we said we're rendering
// a list of triangles (TrangleList).
kvp.Value.Indices.Count / 3);
}
我希望这很清楚。如果您对每个参数和/或概念有任何具体问题,请告诉我。我可以编辑此帖子以澄清这些要点。
希望这有帮助!