Original Post
I am attempting to draw an indexbuffer that should have 2 triangles that make up a rectangle, however nothing appears on the screen. When I created something similar with a straight vertexbuffer (6 vertices) it worked, but I can't get my indexbuffer version to work. I saw the documentation about indexbuffers but I think the problem lies in something before my DrawIndexedPrimitive function.
Quote:
HRESULT InitIB() { // Initialize three vertices for rendering a triangle CUSTOMVERTEX vertices[] = { { 200.0f, 200.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255,0,0),}, { 400.0f, 200.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255,0,0),}, { 400.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255,0,0),}, { 200.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255,0,0),}, }; g_pd3dDevice->CreateIndexBuffer( 3*sizeof(CUSTOMVERTEX), 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &g_pIB, NULL ); DWORD pVertices; g_pIB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ); memcpy( pVertices, vertices, sizeof(vertices) ); g_pIB->Unlock(); return S_OK; } VOID Render() { g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) ); g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice->SetIndices( g_pIB ); g_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, // PrimitiveType 0, // BaseVertexIndex 0, // MinIndex 4, // NumVertices 0, // StartIndex 2 );// PrimitiveCount g_pd3dDevice->EndScene(); } g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }