Sign in to follow this  
EGD Eric

newbie in Direct X: Indexed triangle strips

Recommended Posts

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 [CODE] 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; } [/CODE] and here's the rendering code [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 ); } [/CODE] thanks in advance for anyone who can enlighten me on this subject.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this