// Initialize the index buffer IDirect3DIndexBuffer9* pIndexBuffer = nullptr; device->CreateIndexBuffer(6 * sizeof(DWORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &pIndexBuffer, nullptr); DWORD* indices; pIndexBuffer->Lock(0, 0, (void**)&indices, 0); indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 0; indices[4] = 2; indices[5] = 3; pIndexBuffer->Unlock(); // Set the index buffer device->SetIndices(pIndexBuffer);
// Initialize the index buffer IDirect3DIndexBuffer9* pIndexBuffer = nullptr; device->CreateIndexBuffer(36 * sizeof(DWORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &pIndexBuffer, nullptr); DWORD* indices; pIndexBuffer->Lock(0, 0, (void**)&indices, 0); // Initialize the indices for a cube indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 2; indices[4] = 1; indices[5] = 3; indices[6] = 1; indices[7] = 5; indices[8] = 3; indices[9] = 3; indices[10] = 5; indices[11] = 7; // and so on... pIndexBuffer->Unlock(); // Set the index buffer device->SetIndices(pIndexBuffer);This example shows how to create an index buffer and initialize the indices for a cube. Then it sets the index buffer on the device using the SetIndices method.