创建索引缓冲
HRESULT CreateIndexBuffer(
UINT Length, //索引缓冲区大小,按字节数计算
DWORD Usage, //索引缓冲区属性,和顶点缓冲区相同
D3DFORMAT Format, //索引数组的元素格式,可以使16位或者32位
D3DPOOL Pool, //索引缓冲区内存位置
IDirect3DIndexBuffer9** ppIndexBuffer, //索引缓冲区指针地址
HANDLE* pSharedHandle //保留参数,设为0
);
Format:表示索引数组中的元素格式,他可以是
16
位整数或者
32
位的整数
-
D3DFMT_INDEX16
- Indices are 16 bits each. D3DFMT_INDEX32
- Indices are 32 bits each.
//创建顶点缓冲区
if(FAILED(g_pd3dDevice->CreateVertexBuffer(9*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT,&g_pVB,NULL) ))
{
returnE_FAIL;
}
//创建索引缓冲区
if( FAILED(g_pd3dDevice->CreateIndexBuffer(24*sizeof(WORD),
0, D3DFMT_INDEX16, //索引类型
D3DPOOL_DEFAULT,&g_pIB,NULL) ))
{
returnE_FAIL;
}
保存顶点索引值
//填充顶点缓冲区
VOID*pVertices;
if(FAILED(g_pVB->Lock(0, sizeof(g_Vertices),(void**)&pVertices,0) ) )
return E_FAIL;
memcpy(pVertices,g_Vertices,sizeof(g_Vertices));
g_pVB->Unlock();
//填充索引缓冲区
VOID*pIndices;
if(FAILED(g_pIB->Lock(0, sizeof(g_Indices),(void**)&pIndices,0 )) )
return E_FAIL;
memcpy(pIndices,g_Indices,sizeof(g_Indices));
g_pIB->Unlock();