小弟最近在学Direct3D
这两天一直纳闷那个顶点索引缓存填充的问题
因为我自己填充顶点和索引的时候画出来的立方体总是缺一个角
试了好几次也没有效果
源代码:
lpd3dDevice->CreateVertexBuffer(sizeof(CUSTOMVERTEX)*8,0,D3DFVF_CUSTOM,D3DPOOL_DEFAULT,&lpd3dVertex,NULL);
lpd3dDevice->CreateIndexBuffer(sizeof(WORD) * 36,0,D3DFMT_INDEX16,D3DPOOL_DEFAULT,&lpd3dIndex,NULL);
CUSTOMVERTEX vertex[] =
{
{-20.0,-20.0,-20.0,D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255)},
{20.0,-20.0,-20.0,D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255)},
{20.0,20.0,-20.0,D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255)},
{-20.0,20.0,-20.0,D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255)},
{-20.0,-20.0,20.0,D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255)},
{20.0,-20.0,20.0,D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255)},
{20.0,20.0,20.0,D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255)},
{-20.0,20.0,-20.0,D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255)}};
void * pVertex = NULL;
lpd3dVertex->Lock(0,sizeof(vertex),(void**)&pVertex,0);
memcpy(pVertex,vertex,sizeof(vertex));
lpd3dVertex->Unlock();
WORD Index[] = {0,1,2,0,2,3,0,1,5,0,5,4,0,4,7,0,7,3,2,3,7,2,7,6,1,2,6,1,6,5,4,5,6,4,6,7};
WORD pIndex = NULL; // 设置索引
lpd3dIndex->Lock(0,0,(void*)&pIndex,0);memcpy(pIndex,Index,sizeof(Index));
lpd3dIndex->Unlock();
lpd3dDevice->SetRenderState(D3DRS_LIGHTING,FALSE); //关闭光照
lpd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW); //开启背面消隐
求大神帮助