Reputation: 1610
I am trying to figure out index buffers. I read the MSDN & another thread on it [ Struggling With Vertex And Index Buffers In Direct3D ].
I thought I got it, but in practice, I could not get it to work. I was trying to make a square.
I have 6 vertices:
SimpleVertex vertices[]={ // {Position, Color}
{XMFLOAT3(-0.5f, 0.5f, 0.5f), XMFLOAT4(0.8f, 0.2f, 6.0f, 1.0f)}, // top left
{XMFLOAT3(0.5f, -0.5f, 0.5f), XMFLOAT4(0.8f, 0.2f, 6.0f, 1.0f)}, // bottom right
{XMFLOAT3(-0.5f, -0.5f, 0.5f), XMFLOAT4(0.8f, 0.2f, 6.0f, 1.0f)}, // bottom left
{XMFLOAT3(-0.5f, 0.5f, 0.5f), XMFLOAT4(0.8f, 0.2f, 6.0f, 1.0f)}, // top left
{XMFLOAT3(0.5f, 0.5f, 0.5f), XMFLOAT4(0.8f, 0.2f, 6.0f, 1.0f)}, // top right
{XMFLOAT3(0.5f, -0.5f, 0.5f), XMFLOAT4(0.8f, 0.2f, 6.0f, 1.0f)}, // bottom right
};
& an array of indices:
unsigned short indices[]={
0,3,2, // a d c
0,1,3, // a b d
// a---b
// | \ |
// c---d
}
but that does not display anything. If I change the indices to 0,1,2,3,4,5, it works [defeats the point of the index though].
Anyone know what is wrong with the way I think of indices?
Upvotes: 1
Views: 217
Reputation: 1610
Oops, took me a while after I posted to figure out my problem.
1] I listed the vertices as if I was going to draw it manually. I should have had just 4 vertices [not 6]. The index connects the dots; 1st 3 indices make 1st triangle, 2nd 3 make 2nd triangle.
2] I thought the numbers in the index array represented sides on a shape I imagined [not sure how that even works :P]. They actually represent the position in the array of vertices.
Hope this helps others.
Upvotes: 1