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函数将自己写好的数据写进去。到这里,顶点就算是创建好了。

转载于:https://www.cnblogs.com/minggoddess/p/3494661.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值