newbie in Direct X: Indexed triangle strips

Started by
1 comment, last by EGD Eric 14 years, 9 months ago
I'm trying to draw 2 rows of 4 quads, one on top of the other, using indexed triangle strips, but for some reason, it stops rendering at the 18th index, when there's supposed to be 23 indices in all. as you can see here. I'm starting from the bottom left, working my way right, then placing 2 extra indices on vertex 9, to create degenerate triangles, then moving up and working right to left and stopping on vertex 10 10---11---12---13---14 5----6----7----8----9 0----1----2----3----4 I'm trying to figure out why this could be, any ideas? Here's where I initialize the vertex and index buffers HRESULT InitGeometry() { USHORT *pIndex; // Create the vertex buffer. if( FAILED( g_pd3dDevice->CreateVertexBuffer( NUM_VERTICES * sizeof(Vertex), 0, D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) { return E_FAIL; } // Fill the vertex buffer. Vertex* pVertices; if( FAILED( g_pVB->Lock( 0, sizeof(Vertex) * NUM_VERTICES, (void**)&pVertices, 0 ) ) ) return E_FAIL; //4 squares on each row //bottom row *pVertices++ = Vertex(-10, -5, 0, RGB(0, 230, 0)); *pVertices++ = Vertex(-5, -5, 0, RGB(0, 230, 0)); *pVertices++ = Vertex(0, -5, 0, RGB(0, 230, 0)); *pVertices++ = Vertex(5, -5, 0, RGB(0, 230, 0)); *pVertices++ = Vertex(10, -5, 0, RGB(0, 230, 0)); //middle row for(int i=0; i < 5; i++) *pVertices++ = Vertex(-10 + (i * 5), 0, 0, RGB(0, 120, 200)); //top row for(int i=0; i < 5; i++) *pVertices++ = Vertex(-10 + (i * 5), 5, 0, RGB(0, 120, 200)); g_pVB->Unlock(); //create the index buffer if(FAILED(g_pd3dDevice->CreateIndexBuffer(sizeof(USHORT) * NUM_INDICES, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIB, NULL))) return E_FAIL; g_pIB->Lock(0, sizeof(USHORT) * NUM_INDICES, (void **)&pIndex, 0); //set indices *pIndex++ = 0; *pIndex++ = 5; *pIndex++ = 1; *pIndex++ = 6; *pIndex++ = 2; *pIndex++ = 7; *pIndex++ = 3; *pIndex++ = 8; *pIndex++ = 4; *pIndex++ = 9; *pIndex++ = 9; *pIndex++ = 9; *pIndex++ = 14; *pIndex++ = 8; *pIndex++ = 13; *pIndex++ = 7; *pIndex++ = 12; *pIndex++ = 6; *pIndex++ = 11; *pIndex++ = 5; *pIndex++ = 10; g_pIB->Unlock(); return S_OK; } and here's the rendering code VOID Render() { // Clear the backbuffer and the zbuffer g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 ); // Begin the scene if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { // Setup the world, view, and projection matrices SetupMatrices(); // Render the vertex buffer contents g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(Vertex) ); g_pd3dDevice->SetFVF( FVF_CUSTOMVERTEX ); g_pd3dDevice->SetIndices(g_pIB); g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, NUM_VERTICES, 0, 16); // End the scene g_pd3dDevice->EndScene(); } // Present the backbuffer contents to the display g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); } thanks in advance for anyone who can enlighten me on this subject.
Advertisement
Degenerates count towards your primitive count. You're telling the draw to draw 16 primitives, which it is doing. There are 3 degenerates (4,9,9) (9,9,9) and (9,9,14).
ahaaa! thanks!

This topic is closed to new replies.

Advertisement