Archived

This topic is now archived and is closed to further replies.

FVF

This topic is 5128 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
If you call SetVertexDeclaration, you also have to use a vertex shader. SetVertexDeclaration is there so that D3D knows how to pass information to your vertex shader and how that information should be interpreted. There is not default vertex shader, you have to code one yourself.

If your vertices only have a position and a color, writing a small vertex shader to handle those values isn''t very difficult.

One question that comes to mind though, is why you want to use a vertex declaration if you''re not using a vertex shader?

neneboricua

Share this post


Link to post
Share on other sites
quote:
Original post by neneboricua19
If you call SetVertexDeclaration, you also have to use a vertex shader. SetVertexDeclaration is there so that D3D knows how to pass information to your vertex shader and how that information should be interpreted. There is not default vertex shader, you have to code one yourself.

If your vertices only have a position and a color, writing a small vertex shader to handle those values isn''t very difficult.

One question that comes to mind though, is why you want to use a vertex declaration if you''re not using a vertex shader?

neneboricua



Thanks that clears it up. I was just using the vertex declaration for learning purposes.

Share this post


Link to post
Share on other sites