1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
void drawObject(modelObject* obj)
{
VOID* pVoid; // a void pointer
// create a vertex buffer interface called v_buffer
d3ddev->CreateVertexBuffer(obj->numVertices*sizeof(CUSTOMVERTEX), 0, 0, D3DPOOL_MANAGED, &v_buffer, NULL);
// lock v_buffer and load the vertices into it
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, obj->vertices, sizeof(obj->vertices));
v_buffer->Unlock();
// create a index buffer interface called i_buffer
d3ddev->CreateIndexBuffer(obj->numVertices*sizeof(short), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &i_buffer, NULL);
// lock i_buffer and load the indices into it
i_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, obj->indices, sizeof(obj->indices));
i_buffer->Unlock();
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->SetIndices(i_buffer);
d3ddev->SetVertexDeclaration(Decl);
// Begin passes.
UINT numPasses = 0;
mFX->Begin(&numPasses, 0);
for(UINT i = 0; i < numPasses; i++)
{
mFX->BeginPass(i);
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, obj->numVertices, 0, obj->numFaces);
mFX->EndPass();
}
mFX->End();
}
|