里面主要包含d3dUtility.cpp,d3dUtility.h,cube.cpp。
d3dUtility.cpp,d3dUtility.h与前面demo的是完全一致的,参考http://blog.csdn.net/zero_witty/article/details/51621908
这里主要是cube.cpp,
首先初始化VB,IB全局变量,保存立方体的顶点和索引数据,并初始化全局变量Width,Height,定义窗口的大小
IDirect3DDevice9* Device = 0;
const int Width = 640;
const int Height = 480;
IDirect3DVertexBuffer9* VB = 0;
IDirect3DIndexBuffer9* IB = 0;
接着定义顶点结构,和该结构的灵活顶点类型
struct Vertex{
Vertex();
Vertex(float x, float y, float z)
{
_x = x;
_y = y;
_z = z;
}
float _x, _y, _z;
static const DWORD FVF;
};
const DWORD Vertex::FVF = D3DFVF_XYZ;
再接着便是框架函数Setup()。先创建顶点缓存,索引缓存,并进行填充。
Device->CreateVertexBuffer(8 * sizeof(Vertex), D3DUSAGE_WRITEONLY, Vertex::FVF, D3DPOOL_MANAGED, &VB, 0);
Device->CreateIndexBuffer(36 * sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &IB, 0);
Vertex* vertices;
VB->Lock(0, 0, (void**)&vertices, 0);
vertices[0] = Vertex(-1.0f, -1.0f, -1.0f);
vertices[1] = Vertex(-1.0f, 1.0f, -1.0f);
vertices[2] = Vertex(1.0f, 1.0f, -1.0f);
vertices[3] = Vertex(1.0f, -1.0f, -1.0f);
vertices[4] = Vertex(-1.0f, -1.0f, 1.0f);
vertices[5] = Vertex(-1.0f, 1.0f, 1.0f);
vertices[6] = Vertex(1.0f, 1.0f, 1.0f);
vertices[7] = Vertex(1.0f, -1.0f, 1.0f);
VB->Unlock();
WORD* indices = 0;
IB->Lock(0, 0, (void**)&indices, 0);
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] =