DX SetFVF

自由顶点格式(flexible vertex format,FVF)

http://www.cnblogs.com/xmzyl/articles/1604096.html

 

if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// Draw the triangles in the vertex buffer. This is broken into a few
// steps. We are passing the Vertices down a "stream", so first we need
// to specify the source of that stream, which is our vertex buffer. Then
// we need to let D3D know what vertex shader to use. Full, custom vertex
// shaders are an advanced topic, but in most cases the vertex shader is
// just the FVF, so that D3D knows what type of Vertices we are dealing
// with. Finally, we call DrawPrimitive() which does the actual rendering
// of our geometry (in this case, just one triangle).
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );

// End the scene
g_pd3dDevice->EndScene();
}

 

通过setFVF 按照我的理解 就是告诉shader 他要处理的vertices里面的格式

注释那段话已经说的很详细了 我们自己定义vertex buffer里的结构类型 ,比如D3DFVF_XYZ,D3DFVF_NORMAL,D3DFVF_TEX0.....

很眼熟吧,你规定的这些是可以在shader中使用的。

 

------------------------------------------------------------------------------

因为很多链接会失效,我还是把那段抄过来吧 ,有关fvf的使用步骤

struct CustomerVertex
{
  FLOAT x,y,z,rhw;
  DWORD color; 
};

#define D3DFVF_CUSTOMVERTEX(D3DFVF_XYZRHW|D3DFVF_DIFFUSE) 

 

 

g_pd3dDevice->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
                                 
0
                                 D3DFVF_CUSTOMVERTEX,
                                 D3DPOOL_DEFAULT, 
                                 
&g_pVB, NULL )  

 

CUSTOMVERTEX vertices[]  =
{
  { 
100.0f 400.0f 0.5f 1.0f 0xffff0000 , },
  { 
300.0f ,   50.0f 0.5f 1.0f 0xff00ff00 , }, 
  { 
500.0f 400.0f 0.5f 1.0f 0xff0000ff , },
};

然后将数据写入缓冲区:

 

 

VOID *  pVertices;
if ( FAILED( g_pVB -> Lock(  0 sizeof (vertices), ( void ** ) & pVertices,  0  ) ) )
  
return  E_FAIL;
memcpy( pVertices, vertices, 
sizeof (vertices) );
g_pVB
-> Unlock();

 

 

这里写入的过程用的是Lock函数得到的缓冲区的地址,然后用memcpy函数将自己写好的数据写进去。到这里,顶点就算是创建好了。

你可能感兴趣的:(set)