Does FVF have to be used when not using a programmable vertex shader? Or is it possible to use an array of D3DVERTEXELEMENT9 sructures?
I tryed to replace the #define D3DFVF_xyz .. etc with a D3DVERTEXELEMENT9, and when i tryed to render with it, nothing appeared on the screen. Do i have to set some sort of default vertex shader for use with the fixed function pipeline? or must i only use FVF
For example, consider this code from the matrices tutorial in the dx9 sdk
struct CUSTOMVERTEX
{
FLOAT x, y, z; // The untransformed, 3D position for the vertex
float color; // The vertex color
};
// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
// i added this
D3DVERTEXELEMENT9 vert[] =
{ {0, 0 ,D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_POSITION, 0},
{0, 3*sizeof(float),D3DDECLTYPE_FLOAT1,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_COLOR, 0},
D3DDECL_END()
};
Is the vert structure the same as D3DFVF_CUSTOMVERTEX? or have i done something wrong there?
I then use the vert structure like so
IDirect3DVertexDeclaration9* vertex_decl; //global
if( FAILED( g_pd3dDevice->CreateVertexDeclaration(vert, &vertex_decl)))
MessageBox(0,"error","error",MB_OK);
// Create the vertex buffer.
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
0, 0,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
//then in the render function i have..
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetVertexDeclaration(vertex_decl);
// g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
If i uncomment the SetFVF and comment out the SetVertexDeclaration, the trianlge shows up corectly, but with SetFVF commented out, and SetVertexDeclaration uncommented, it does not show up at all, i just get a black screen which closes itself as soon as the program starts. Am i dong something wrong? or is SetFVF the only way to draw something when using the Fixed Function Pipeline?
[edited by - quant on November 28, 2003 6:10:40 PM]