Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  user27811 Oct 18 '12 at 5:58
add comment

2 Answers 2

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

 GraphicsDevice.RasterizerState = RasterizerState.CullNone;
share|improve this answer
    
Didn't change anything. –  Deukalion Oct 17 '12 at 10:56
add comment
up vote 0 down vote accepted

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
    );
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.