开发者

Directx9 methods of drawing models

I was wondering if there is any other method beside the classical

DrawIndexedPrimitive
Dra开发者_如何学GowIndexedPrimitiveUP
DrawPrimitive
DrawPrimitiveUP
DrawRectPatch
DrawTriPatch 

for drawing models on the screen.


if you mean that model is a mesh (set of vertex and textures) and you have file with that model you can try something like this:

// Loading the mesh
LPD3DXBUFFER materialBuffer = NULL;
DWORD numMaterials = 0;
LPD3DXMESH mesh = NULL;
hr=D3DXLoadMeshFromX("d:\\temp\\tiger.x", D3DXMESH_SYSTEMMEM, 
    d3dDevice, NULL, 
    &materialBuffer,NULL, &numMaterials, 
    &mesh );
if(FAILED(hr))
    THROW_ERROR_AND_EXIT("hr=D3DXLoadMeshFromX");

// Loading the material buffer
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)materialBuffer->GetBufferPointer();
// Holding material and texture pointers
D3DMATERIAL9 *meshMaterials = new D3DMATERIAL9[numMaterials];
LPDIRECT3DTEXTURE9 *meshTextures  = new LPDIRECT3DTEXTURE9[numMaterials];   
// Filling material and texture arrays
for (DWORD i=0; i<numMaterials; i++)
{
    // Copy the material
    meshMaterials[i] = d3dxMaterials[i].MatD3D;

    // Set the ambient color for the material (D3DX does not do this)
    meshMaterials[i].Ambient = meshMaterials[i].Diffuse;

    // Create the texture if it exists - it may not
    meshTextures[i] = NULL;
    if (d3dxMaterials[i].pTextureFilename)
        D3DXCreateTextureFromFile(d3dDevice, d3dxMaterials[i].pTextureFilename, &meshTextures[i]);
}

materialBuffer->Release();

//render mesh
d3dDevice->Clear(0,NULL,D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,255),1.0f,0);
            // Turn on wireframe mode
            d3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
            d3dDevice->BeginScene();
        for (DWORD i=0; i<numMaterials; i++)
        {
            // Set the material and texture for this subset
            d3dDevice->SetMaterial(&meshMaterials[i]);
            d3dDevice->SetTexture(0,meshTextures[i]);
            // Draw the mesh subset
            mesh->DrawSubset( i );
        }

        d3dDevice->EndScene();
        d3dDevice->Present(NULL, NULL, NULL, NULL);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜