// Vertices struct Vertex { float x, y, z; DWORD color; }; Vertex triangle[] = { {-1.0f, 0.0f, 0.0f, 0xFFFF0000}, // red { 1.0f, 0.0f, 0.0f, 0xFF00FF00}, // green { 0.0f, 1.0f, 0.0f, 0xFF0000FF} // blue }; // Indices WORD indices[] = {0, 1, 2}; // Draw device->DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE::D3DPT_TRIANGLELIST, 0, 3, 1, indices, D3DFMT_INDEX16, triangle, sizeof(Vertex));
// Vertices struct Vertex { float x, y, z; DWORD color; }; Vertex cube[] = { // front {-1.0f, -1.0f, -1.0f, 0xFF0000FF}, // blue {-1.0f, 1.0f, -1.0f, 0xFF00FF00}, // green { 1.0f, 1.0f, -1.0f, 0xFFFFFF00}, // yellow { 1.0f, -1.0f, -1.0f, 0xFFFF0000}, // red // back {-1.0f, -1.0f, 1.0f, 0xFF800080}, // purple {-1.0f, 1.0f, 1.0f, 0xFF008000}, // dark green { 1.0f, 1.0f, 1.0f, 0xFF808000}, // olive { 1.0f, -1.0f, 1.0f, 0xFF800000} // dark red }; // Indices WORD indices[] = { 0, 1, 2, 2, 3, 0, // front 1, 5, 6, 6, 2, 1, // top 5, 4, 7, 7, 6, 5, // back 4, 0, 3, 3, 7, 4, // bottom 3, 2, 6, 6, 7, 3, // right 4, 5, 1, 1, 0, 4 // left }; // Draw device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 8, 12, indices, D3DFMT_INDEX16, cube, sizeof(Vertex));This code creates a set of 8 vertices and an index buffer that defines a cube, then calls DrawIndexedPrimitiveUP to render it. The D3DPT_TRIANGLELIST parameter specifies the type of primitive we are rendering (in this case, a set of triangles). In both examples, we passed the device object (of type LPDIRECT3DDEVICE9) as the first parameter to the DrawIndexedPrimitiveUP function, indicating that we want to render the primitives on that device.