Directx9绘制模型的方法
Directx9 methods of drawing models
我想知道是否有任何其他方法,除了经典的
DrawIndexedPrimitive
DrawIndexedPrimitiveUP
DrawPrimitive
DrawPrimitiveUP
DrawRectPatch
DrawTriPatch
在屏幕上绘制模型
如果你的意思是模型是一个网格(顶点和纹理的集合),你可以尝试这样做:
// 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);
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 通过方法访问结构
- 最小硬币更换问题(自上而下方法)
- Qt - QVector 和模型视图 - 从列表视图获取自定义类的最佳方法是什么?
- 在确保遵循 SOLID 的同时,为 C++ 中的许多类设计持久性模型的最佳方法是什么?
- 在模型中保存整数的方法,与QStyledItemDelegate兼容
- 编译错误,未创建函数/方法! 对于 brms 模型
- 是否有一种方法可以将QTableView模型转换为QstandardItemModel
- OpenGL-更新模型信息的最有效方法(例如模型矩阵)
- 模型中虚拟索引实现的替代方法
- 通过委托方法让C++模型通知Objective-C++控制器
- 跨平台最佳 MVC 模型到控制器消息传递方法(C#、Objective-C++)
- Qt模型视图:当数据存储和更改数据时,更新模型和视图的正确方法是什么::vector
- 调试数据方法 Q抽象表模型
- 我正在寻找一种在从模型中删除并重新添加修改后的可提取对象后操作 iloextract 对象的方法
- 从非托管C++调用C#方法,该方法传递回一个完整的对象模型
- Directx9绘制模型的方法
- 概括模型中的数据访问.避免宏观的方法
- 在OpenGL 4.0中,是否有一种围绕局部坐标(即从模型视图矩阵)旋转的标准方法
- 在3D场景中存储模型位置的好方法是什么?