# Drawing multiple triangles at once isn't working

I'm trying to draw multiple triangles at once to make up a "shape". I have a class that has an array of VertexPositionColor, an array of Indexes (rendered by this Triangulation class):

http://www.xnawiki.com/index.php/Polygon_Triangulation

So, my "shape" has multiple points of VertexPositionColor but I can't render each triangle in the shape to "fill" the shape. It only draws the first triangle.

struct ShapeColor
{
// Properties (not all properties)
VertexPositionColor[] Points;
int[] Indexes;
}


First method that I've tried, this should work since I iterate through the index array that always are of "3s", so they always contain at least one triangle.

//render = ShapeColor

for (int i = 0; i < render.Indexes.Length; i += 3)
{
device.DrawUserIndexedPrimitives<VertexPositionColor>
(
PrimitiveType.TriangleList,
new VertexPositionColor[] { render.Points[render.Indexes[i]], render.Points[render.Indexes[i+1]], render.Points[render.Indexes[i+2]] },
0,
3,
new int[] { 0, 1, 2 },
0,
1
);
}


or the method that should work:

device.DrawUserIndexedPrimitives<VertexPositionColor>
(
PrimitiveType.TriangleList,
render.Points,
0,
render.Points.Length,
render.Indexes,
0,
render.Indexes.Length / 3,
VertexPositionColor.VertexDeclaration
);


No matter what method I use this is the "typical" result from my Editor (in Windows Forms with XNA)

It should show a filled shape, because the indexes are right (I've checked a dozen of times)

I simply click the screen (gets the world coordinates, adds a point from a color, when there are 3 points or more it should start filling out the shape, it only draws the lines (different method) and only 1 triangle). The Grid isn't rendered with "this" shape.

Any ideas?

• how are you populating the int[] Indexes; array? – Ken Oct 17 '12 at 13:07
• Please insert the code for shape generation. Without this, we can't see if there are enough indices created, or if they are created correctly And please do not use such code as in your for loop: it slows down your rendering, consumes memory for nothing and is not readable. – 0xBADF00D Oct 18 '12 at 5:58

Looks like it might be a face culling issue. Try turning off face culling:

 GraphicsDevice.RasterizerState = RasterizerState.CullNone;

• Didn't change anything. – Deukalion Oct 17 '12 at 10:56

Solution:

foreach(ShapeColor render in Shapes)
{
device.DrawUserIndexedPrimitives<VertexPositionColor>
(
PrimitiveType.TriangleList,
render.Points,
0,
render.Points.Length,
render.Indexes,
0,
render.Indexes.Length / 3,
VertexPositionColor.VertexDeclaration
);
}