// Create vertex buffer CUSTOMVERTEX vertices[] = { { 0.0f, 1.0f, 0.0f }, { 1.0f, -1.0f, 0.0f }, { -1.0f, -1.0f, 0.0f } }; LPDIRECT3DVERTEXBUFFER9 vertexBuffer; d3dDevice->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_DEFAULT, &vertexBuffer, NULL); void* pVertices; vertexBuffer->Lock(0, sizeof(vertices), (void**)&pVertices, 0); memcpy(pVertices, vertices, sizeof(vertices)); vertexBuffer->Unlock(); // Create index buffer WORD indices[] = { 0, 1, 2 }; LPDIRECT3DINDEXBUFFER9 indexBuffer; d3dDevice->CreateIndexBuffer(3 * sizeof(WORD), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &indexBuffer, NULL); void* pIndices; indexBuffer->Lock(0, sizeof(indices), (void**)&pIndices, 0); memcpy(pIndices, indices, sizeof(indices)); indexBuffer->Unlock(); // Draw triangle d3dDevice->SetStreamSource(0, vertexBuffer, 0, sizeof(CUSTOMVERTEX)); d3dDevice->SetFVF(CUSTOMFVF); d3dDevice->SetIndices(indexBuffer); d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 3, 0, 1);
// Create vertex buffer CUSTOMVERTEX vertices[] = { { -1.0f, 1.0f, -1.0f }, { 1.0f, 1.0f, -1.0f }, { -1.0f, -1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, { -1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, { -1.0f, -1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, // Repeat for each vertex }; LPDIRECT3DVERTEXBUFFER9 vertexBuffer; d3dDevice->CreateVertexBuffer(24 * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_DEFAULT, &vertexBuffer, NULL); void* pVertices; vertexBuffer->Lock(0, sizeof(vertices), (void**)&pVertices, 0); memcpy(pVertices, vertices, sizeof(vertices)); vertexBuffer->Unlock(); // Create index buffer WORD indices[] = { 0, 1, 3, 0, 3, 2, // Repeat for each face }; LPDIRECT3DINDEXBUFFER9 indexBuffer; d3dDevice->CreateIndexBuffer(36 * sizeof(WORD), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &indexBuffer, NULL); void* pIndices; indexBuffer->Lock(0, sizeof(indices), (void**)&pIndices, 0); memcpy(pIndices, indices, sizeof(indices)); indexBuffer->Unlock(); // Draw cube d3dDevice->SetStreamSource(0, vertexBuffer, 0, sizeof(CUSTOMVERTEX)); d3dDevice->SetFVF(CUSTOMFVF); d3dDevice->SetIndices(indexBuffer); d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12);These examples use the DirectX 9 package library (d3d9.h and d3dx9.h) and assume that the necessary headers, libraries, and initialization code have been included and configured properly.