Hi,
I was just mucking around with triangle strips in order to better understand them. I have read from tutorials and other posts that within the function
DrawIndexedPrimitive(THIS_ D3DPRIMITIVETYPE,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
primCount refers obviously to the amount of primitves (or triangles) in your triangle strip. Well I have created a strip made up of 6 vertices, hence 4 triangles, and 12 indicies. But if i set primCount to 4, only 2 triangles show up, and just from mucking around i figured out that i need to set primCount to 10 to show my 4 triangles based on my code. I believe there to be something wrong with my code, maybe the winding of my triangles. Im a bit confused with winding practises in triangle lists, I read conflicting information stating it should be CW or CCW or alternating beteen CW/CCW. I tried the first two, and they didnt work properly, but using the alternations did. Except in all cases, i need to set primCount to show all 4 triangles (even thought they display all weird in CW or CCW situations). Heres my code:
For setting everything up
vertices = new MY_VERTEX[6];
indices = new WORD[12];
D3DDev->CreateVertexBuffer(6 * sizeof(MY_VERTEX), D3DUSAGE_WRITEONLY, MY_FVF, D3DPOOL_MANAGED, &vertexBuffer, NULL);
vertexBuffer->Lock(0, 0, (void**)&vertices, 0);
vertices[0].x = 0.0f;
vertices[0].y = 0.0f;
vertices[0].z = 0.0f;
vertices[0].colour = D3DCOLOR_XRGB(0,0, 255);
vertices[1].x = 10.0f;
vertices[1].y = 0.0f;
vertices[1].z = 0.0f;
vertices[1].colour = D3DCOLOR_XRGB(0,0, 255);
vertices[2].x = 20.0f;
vertices[2].y = 0.0f;
vertices[2].z = 0.0f;
vertices[2].colour = D3DCOLOR_XRGB(0,0, 255);
vertices[3].x = 0.0f;
vertices[3].y = 0.0f;
vertices[3].z = 10.0f;
vertices[3].colour = D3DCOLOR_XRGB(0,0, 255);
vertices[4].x = 10.0f;
vertices[4].y = 0.0f;
vertices[4].z = 10.0f;
vertices[4].colour = D3DCOLOR_XRGB(0,0, 255);
vertices[5].x = 20.0f;
vertices[5].y = 0.0f;
vertices[5].z = 10.0f;
vertices[5].colour = D3DCOLOR_XRGB(255,0, 0);
vertexBuffer->Unlock();
// n of tri = 4
D3DDev->CreateIndexBuffer(4 * 3 * sizeof(DWORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &indexBuffer, NULL);
indices = NULL;
indexBuffer->Lock(0, 0, (void**)&indices, 0);
indices[0] = 0;
indices[1] = 3;
indices[2] = 1;
indices[3] = 3;
indices[4] = 1;
indices[5] = 4;
indices[6] = 1;
indices[7] = 4;
indices[8] = 2;
indices[9] = 4;
indices[10] = 2;
indices[11] = 5;
indexBuffer->Unlock();
For rendering
D3DDev->SetStreamSource(0, vertexBuffer, 0, sizeof(MY_VERTEX));
D3DDev->SetFVF(MY_FVF);
D3DDev->SetIndices(indexBuffer);
D3DDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, 6, 0, 10);
And essentially this is the layout of my vertices,
3--4--5
|\ |\ |
| \| \|
0--1--2
The reason for my increasing by row approach is that I'm planning to try and create a terrain generator based on triangle strips and heightmaps, but I cant even get a simple 2 quad strip to work.
Oh also, while im here, would anybody be able to link me to a tutorial which discusses terrain generation in regards to those degenerate triangles. I understood mostly the other parts of various other tutorials. I was a bit confused with the degenerate triangles sections though.
Hope somebody can help me identify my problem. Thanks in advance!
[Edited by - fuchi on January 6, 2008 2:53:01 PM]