Drawing multiple triangles at once isn't working

Posted by Deukalion on Game Development See other posts from Game Development or by Deukalion
Published on 2012-10-17T09:49:19Z Indexed on 2012/10/17 11:23 UTC
Read the original article Hit count: 339

Filed under:
|
|
|
|

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)

Result in my Game Editor

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?

© Game Development or respective owner

Related posts about XNA

Related posts about rendering