Hi every one!
I'm currently working on directX, and i'm facing a problem.
When i create a cube with an array of vertices and an array of indices,
i can render it with no problem with a "global" drawIndexedPrimitives call.
But if i try to render it triangle by triangle, i get huge problems.
First, here is my cube declaration :
vertices = new CustomVertex.PositionColored[8];
vertices[0].Position = new Vector3(0f, 0f, 0f);
vertices[0].Color = Color.Blue.ToArgb();
vertices[1].Position = new Vector3(0f, 10f, 0f);
vertices[1].Color = Color.Red.ToArgb();
vertices[2].Position = new Vector3(10f, 10f, 0f);
vertices[2].Color = Color.Green.ToArgb();
vertices[3].Position = new Vector3(10f, 0f, 0f);
vertices[3].Color = Color.White.ToArgb();
vertices[4].Position = new Vector3(0f, 0f, 10f);
vertices[4].Color = Color.Yellow.ToArgb();
vertices[5].Position = new Vector3(0f, 10f, 10f);
vertices[5].Color = Color.LightGray.ToArgb();
vertices[6].Position = new Vector3(10f, 10f, 10f);
vertices[6].Color = Color.Purple.ToArgb();
vertices[7].Position = new Vector3(10f, 0f, 10f);
vertices[7].Color = Color.LightBlue.ToArgb();
indices = new short[36];
indices[0]=0;
indices[1]=1;
indices[2]=2;
indices[3]=3;
indices[4]=0;
indices[5]=2;
indices[6]=7;
indices[7]=6;
indices[8]=5;
indices[9]=4;
indices[10]=7;
indices[11]=5;
indices[12]=3;
indices[13]=2;
indices[14]=6;
indices[15]=7;
indices[16]=3;
indices[17]=6;
indices[18]=4;
indices[19]=5;
indices[20]=1;
indices[21]=0;
indices[22]=4;
indices[23]=1;
indices[24]=1;
indices[25]=5;
indices[26]=6;
indices[27]=2;
indices[28]=1;
indices[29]=6;
indices[30]=4;
indices[31]=0;
indices[32]=3;
indices[33]=7;
indices[34]=4;
indices[35]=3;
Then to render, i first prepare the rendering :
device.VertexFormat = CustomVertex.PositionColored.Format;
device.SetStreamSource(0, vb, 0);
device.Indices = ib;
And finally i render the whole cube with :
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 8, 0, 12);
which actually works perfectly.
But my point is i want to be able to render the cube triangle by triangle, doing something like this :
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 3, 0, 1);
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 3, 3, 0, 1);
...
where the idea is to keep the vertex buffer, and render each triangle by taking each time the three next indices in the indexbuffer.
But this doesn't work. I tried many paramaters with no good result.
Basically the first triangle renders as normal, but the second is not displayed, and so on...
I also get some very strange triangles sometimes, as if i was doing wrong with the indices.
I tried to disable culling to see if they were created not facing camera, but no better result.
Please may someone help me?
[Edited by - vk_phoenixfr on October 21, 2005 4:16:18 AM]