代码
//
定义顶点结构:
struct ColorVertex
{
ColorVertex()
{
}
ColorVertex( float x, float y, float z, D3DCOLOR c)
{
_x = x;
_y = y;
_z = z;
_color = c;
}
float _x, _y, _z;
D3DCOLOR _color;
static const DWORD FVF;
};
const DWORD ColorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
// 声明一个顶点缓存接口
IDirect3DVertexBuffer9 * triangle = 0 ;
// 创建顶点缓存
Device -> CreateVertexBuffer(
3 * sizeof (ColorVertex),
D3DUSAGE_WRITEONLY,
ColorVertex::FVF,
D3DPOOL_MANAGED,
& triangle,
0
);
// 访问顶点缓存内容
ColorVertex * colorVertices;
triangle -> Lock( 0 , 0 , ( void ** ) & triangle, 0 );
colorVertices[ 0 ] = ColorVertex( - 1.0f , 0.0f , 2.0f , D3DCOLOR_XRGB( 255 , 0 , 0 ));
colorVertices[ 0 ] = ColorVertex( 0.0f , 1.0f , 2.0f , D3DCOLOR_XRGB( 0 , 255 , 0 ));
colorVertices[ 0 ] = ColorVertex( 1.0f , 0.0f , 2.0f , D3DCOLOR_XRGB( 0 , 0 , 255 ));
triangle -> Unlock();
// 绘制
Device -> SetFVF(ColorVertex::FVF);
Device -> SetStreamSource( 0 , triangle, 0 , sizeof (ColorVertex));
D3DXMatrixTranslation( & WorldMatrix, - 1.25f , 0.0f , 0.0f );
Device -> SetTransform(D3DTS_WORLD, & WorldMatrix);
Device -> SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
Device -> DrawPrimitive(D3DPT_TRIANGLELIST, 0 , 1 );
struct ColorVertex
{
ColorVertex()
{
}
ColorVertex( float x, float y, float z, D3DCOLOR c)
{
_x = x;
_y = y;
_z = z;
_color = c;
}
float _x, _y, _z;
D3DCOLOR _color;
static const DWORD FVF;
};
const DWORD ColorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
// 声明一个顶点缓存接口
IDirect3DVertexBuffer9 * triangle = 0 ;
// 创建顶点缓存
Device -> CreateVertexBuffer(
3 * sizeof (ColorVertex),
D3DUSAGE_WRITEONLY,
ColorVertex::FVF,
D3DPOOL_MANAGED,
& triangle,
0
);
// 访问顶点缓存内容
ColorVertex * colorVertices;
triangle -> Lock( 0 , 0 , ( void ** ) & triangle, 0 );
colorVertices[ 0 ] = ColorVertex( - 1.0f , 0.0f , 2.0f , D3DCOLOR_XRGB( 255 , 0 , 0 ));
colorVertices[ 0 ] = ColorVertex( 0.0f , 1.0f , 2.0f , D3DCOLOR_XRGB( 0 , 255 , 0 ));
colorVertices[ 0 ] = ColorVertex( 1.0f , 0.0f , 2.0f , D3DCOLOR_XRGB( 0 , 0 , 255 ));
triangle -> Unlock();
// 绘制
Device -> SetFVF(ColorVertex::FVF);
Device -> SetStreamSource( 0 , triangle, 0 , sizeof (ColorVertex));
D3DXMatrixTranslation( & WorldMatrix, - 1.25f , 0.0f , 0.0f );
Device -> SetTransform(D3DTS_WORLD, & WorldMatrix);
Device -> SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
Device -> DrawPrimitive(D3DPT_TRIANGLELIST, 0 , 1 );