19,468
社区成员
发帖
与我相关
我的任务
分享
//顶点声明
OnD3D9CreateDevice()
{
....
D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
D3DDECL_END()
};
V_RETURN( pd3dDevice->CreateVertexDeclaration( decl, &g_pVertexDeclaration ) );
..
}
//顶点结构
OnD3D9ResetDevice()
{
......
// Setup render states
pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Create and initialize vertex buffer测试,用最简单的三角形
V_RETURN( pd3dDevice->CreateVertexBuffer( 3 * sizeof( D3DXVECTOR2 ),
0, 0,
D3DPOOL_DEFAULT, &g_pVB, NULL ) );
D3DXVECTOR2* pVertices;
V_RETURN( g_pVB->Lock( 0, 0, ( void** )&pVertices, 0 ) );
for( WORD i =0; i<3; i++)
{
*pVertices++= D3DXVECTOR2( 200*sinf( i*D3DX_PI/4.0)+300, 200*cosf( i*D3DX_PI/4.0)+250);
}
V_RETURN( hr = g_pVB->Unlock() );
//Create and initialize index buffer
WORD* pIndices;
V_RETURN( pd3dDevice->CreateIndexBuffer( 3 * sizeof( WORD ),
0, D3DFMT_INDEX16,
D3DPOOL_DEFAULT, &g_pIB, NULL ) );
V_RETURN( g_pIB->Lock( 0, 0, ( void** )&pIndices, 0 ) );
pIndices[0] = ( WORD )( 0 );
pIndices[1] = ( WORD )( 1 );
pIndices[2] = ( WORD )( 2 );
V_RETURN( g_pIB->Unlock() );
......
}
//画三角形
OnD3D9FrameRender()
{
..
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
pd3dDevice->SetVertexDeclaration( g_pVertexDeclaration );
pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( D3DXVECTOR2 ) );
pd3dDevice->SetIndices( g_pIB );
V( pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 3,
0, 1 ) );
..
}