win32的 WORD 类详解
例:一段正方体的初始化
其他参数:
struct TriangleVertex
{
float x, y, z;
DWORD color;
};
LPDIRECT3DDEVICE9 m_pDevice;
LPDIRECT3DVERTEXBUFFER9 m_pTriangleVB;
LPDIRECT3DINDEXBUFFER9 m_pSquareIB;
//初始化代码
void Init(LPDIRECT3DDEVICE9 pDevice)
{
m_pDevice = pDevice;
float f=15.0f;
TriangleVertex tvVertices[] =
{
//顶面
{-f, f, -f, D3DCOLOR_XRGB(0, 0, 255),}, //Vertex 0 - Blue
{-f, f, f, D3DCOLOR_XRGB(255, 0, 0),}, //Vertex 1 - Red
{f, f, -f, D3DCOLOR_XRGB(255, 0, 0),}, //Vertex 2 - Red
{f, f, f, D3DCOLOR_XRGB(0, 255, 0),}, //Vertex 3 - Green
//底面
{f, -f, -f, D3DCOLOR_XRGB(0, 255, 0),}, //Vertex 4 - Green
{f, -f, f, D3DCOLOR_XRGB(0, 0, 255),}, //Vertex 5 - Blue
{-f, -f, -f, D3DCOLOR_XRGB(255, 0, 0),}, //Vertex 6 - Red
{-f, -f, f, D3DCOLOR_XRGB(0, 255, 0),}, //Vertex 7 - Green
};
// 创建顶点缓冲
m_pDevice->CreateVertexBuffer(sizeof(tvVertices), D3DUSAGE_WRITEONLY,
D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &m_pTriangleVB, NULL);
// 创建索引缓冲
m_pDevice->CreateIndexBuffer( 36 * sizeof(WORD), D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pSquareIB, NULL );
// 设置顶点数据
void *pVertices = NULL;
m_pTriangleVB->Lock( 0, sizeof(TriangleVertex), &pVertices, 0 );
memcpy(pVertices, tvVertices, sizeof(tvVertices));
m_pTriangleVB->Unlock();
WORD wIndices[] ={ 0,1,2,1,3,2,
0,4,6,0,2,4,
2,5,4,2,3,5,
3,7,5,3,1,7,
1,6,7,1,0,6,
4,5,7,7,6,4 };
WORD *pIndices = NULL;
m_pSquareIB->Lock( 0, sizeof(wIndices), (void**)&pIndices, 0 );
memcpy( pIndices, wIndices, sizeof(wIndices) ) ;
m_pSquareIB->Unlock();
}
///求WORD 应用的详细说明