首页 > 解决方案 > 在 Visual Studio C++ 上加载大量网格滞后

问题描述

现在我用 Visual Studio C++ Directx 9 为学校项目制作保龄球游戏,问题是,我试图加载很多保龄球瓶,这使得游戏非常滞后。有什么方法可以使游戏优化(不滞后)?我这样做

D3DXMATERIAL* tempMaterials_pin =
    (D3DXMATERIAL*)bufshipMaterial_pin->GetBufferPointer();

materials_pin = new D3DMATERIAL9[numMaterials_pin];

textures_pin = new LPDIRECT3DTEXTURE9[numMaterials_pin];

for (DWORD i = 0; i < numMaterials_pin; i++) {
    materials_pin[i] = tempMaterials_pin[i].MatD3D;
    materials_pin[i].Ambient = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f);
    materials_pin[i].Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 0.2f);
    if (FAILED(
        D3DXCreateTextureFromFileA(d3ddev, tempMaterials_pin[i].pTextureFilename, &textures_pin[i]))) {
        textures_pin[i] = NULL;
    }
}
for (DWORD i = 0; i < numMaterials_pin; i++) {
            d3ddev->SetMaterial(&materials_pin[i]);
            if (textures_pin[i] != NULL) {
                d3ddev->SetTexture(0, textures_pin[i]);
            }
        }

        D3DXMATRIX matTranslate_pin;
        for (int j = 0; j < 10; j++) {
            D3DXMatrixTranslation(&matTranslate_pin, 0.0f, 0.0f, 0.0f);
            d3ddev->SetTransform(D3DTS_WORLD, &(matTranslate_pin));

            for (DWORD i = 0; i < numMaterials_pin; i++) {
                mesh_pin[j]->DrawSubset(i);
            }
        }

我还没有设置坐标,因为我仍然试图加载网格并且它使游戏变得滞后我做错了吗?

标签: visual-c++meshlagdirectx-9

解决方案


推荐阅读