Directx9绘制模型的方法

发布于 2024-12-06 00:50:01 字数 174 浏览 1 评论 0原文

经典方法之外是否还有其他方法。

DrawIndexedPrimitive
DrawIndexedPrimitiveUP
DrawPrimitive
DrawPrimitiveUP
DrawRectPatch
DrawTriPatch 

我想知道除了在屏幕上绘制模型的

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

DrawIndexedPrimitive
DrawIndexedPrimitiveUP
DrawPrimitive
DrawPrimitiveUP
DrawRectPatch
DrawTriPatch 

for drawing models on the screen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小沫ゞ 2024-12-13 00:50:01

如果您的意思是该模型是一个网格(顶点和纹理的集合)并且您有该模型的文件,您可以尝试如下操作:

// 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文