How do I draw a single Triangle with XNA and fill it with a Texture?
Posted
by
Deukalion
on Game Development
See other posts from Game Development
or by Deukalion
Published on 2012-06-23T17:02:16Z
Indexed on
2012/06/23
21:25 UTC
Read the original article
Hit count: 315
I'm trying to wrap my head around:
http://msdn.microsoft.com/en-us/library/bb196409.aspx
I'm trying to create a method in XNA that renders a single Triangle, then later make a method that takes a list of Triangles and renders them also. But it isn't working. I'm not understanding what all the things does and there's not enough information.
My methods:
// Triangle is a struct with A, B, C (didn't include) A, B, C = Vector3
public static void Render(GraphicsDevice device, List<Triangle> triangles, Texture2D texture)
{
foreach (Triangle triangle in triangles)
{
Render(device, triangle, texture);
}
}
public static void Render(GraphicsDevice device, Triangle triangle, Texture2D texture)
{
BasicEffect _effect = new BasicEffect(device);
_effect.Texture = texture;
_effect.VertexColorEnabled = true;
VertexPositionColor[] _vertices = new VertexPositionColor[3];
_vertices[0].Position = triangle.A;
_vertices[1].Position = triangle.B;
_vertices[2].Position = triangle.B;
foreach (var pass in _effect.CurrentTechnique.Passes)
{
pass.Apply();
device.DrawUserIndexedPrimitives<VertexPositionColor>
(
PrimitiveType.TriangleList,
_vertices,
0,
_vertices.Length,
new int[] { 0, 1, 2 }, // example has something similiar, no idea what this is
0,
3 // 3 = gives me an error, 1 = works but no results
);
}
}
© Game Development or respective owner