Sign in to follow this  
Eddie Zehoo

Weird Problem with SetFVF

Recommended Posts

Eddie Zehoo    122
Hi! I keep running into this problem where during my game, VC++ spits out the following error "Direct3D9: (ERROR) :Current vertex shader declaration doesn't match VB's FVF" in the Debug section. Previously I used HRESULT hResult=lp_3DDevice->CreateVertexBuffer (6 * sizeof(CUSTOMVERTEX),D3DUSAGE_WRITEONLY ,D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1,D3DPOOL_DEFAULT, &lp_PrimaryVertexBuffer,NULL); lp_3DDevice->SetVertexShader (NULL); lp_3DDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); and everything ran fine, but then I decided to get rid of RHW, and use orthographic projection, So I changed my FVF flags and the code became : HRESULT hResult=lp_3DDevice->CreateVertexBuffer (6 * sizeof(CUSTOMVERTEX),D3DUSAGE_WRITEONLY ,D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1,D3DPOOL_DEFAULT, &lp_PrimaryVertexBuffer,NULL); lp_3DDevice->SetVertexShader (NULL); lp_3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); But now Direct3D complains that my "Current vertex shader declaration doesn't match VB's FVF" .. , and then a subsequent "DrawPrimitive Failed". I'm using Direct3D 9, which means I can't simply use SetVertexShader(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1) because it only takes in a pointer. I've spent countless hours on this.. Whats the problem with the code? All and any help appreciated! Regards, Ed Zehoo

Share this post


Link to post
Share on other sites
IFooBar    906
WHat are you passing into IDirect3DDevice9::SetStreamSource? The stride parameter should be the same as the implied size the FVFs give direct3d. Your fvf is xyz/normal/tex so that's 3 + 3 + 2 floats and that's 8 * 4 bytes = 32.

Are you sure your vertex struct dosnt have any extra information?

Share this post


Link to post
Share on other sites
Eddie Zehoo    122
Hi IFoobar,

The size of the struct is definitely correct, since I'm using the sizeof macro.

lp_3DDevice->SetStreamSource (0,lp_PrimaryVertexBuffer,0,sizeof(CUSTOMVERTEX));

Anyway, I have narrowed down the problem to this : Basically if RHW was specified and used, SetFVF has no problems. Once RHW is taken out, Direct3D 9 then says that my vertex shader declaration doesnt match VB's FVF, although I am 200% sure it does.

I'm not sure if anyone else got this same problem, but I am *thinking* once you switch to non-RHW projection, maybe Direct3D requires you to write a vertex shader and set it via SetVertexShader, and totally ignore whatever you set with SetFVF (the fixed function vertex pipeline)...


Please help, IFoobar, anyone!! This is driving me nuts

Regards,
Ed Zehoo

Share this post


Link to post
Share on other sites
__Daedalus__    480
You have already asked that here in the Game Programming forum.

Please post your vertex structure. If you remove RHW from your FVF declaration then you must remove it from your vertex structure, CUSTOMVERTEX, also.

Share this post


Link to post
Share on other sites
Opalm    122
HI,

I have a question about D3D, FVF rendering~{!#~}

I have try to use the following code,
struct CUSTOMVERTEX{ 
float x, y, z;
DWORD color;
};

CUSTOMVERTEX g_Vertices[] =
{
{ -1.0f,-1.0f, 0.0f, 0xffff0000, },
{ 1.0f,-1.0f, 0.0f, 0xff0000ff, },
{ 0.0f, 1.0f, 0.0f, 0xffffffff, },
};

g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
0,
D3DFVF_XYZ|D3DFVF_DIFFUSE,
D3DPOOL_DEFAULT,
&g_pVB ) );

VOID* pVertices;
g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 ) ) ;
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
g_pVB->Unlock();

g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetVertexShader( D3DFVF_XYZ|D3DFVF_DIFFUSE);
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );


it dose not work correctly, but when I use following code it
work correctly.
struct CUSTOMVERTEX{ 
float x, y, z, rhw;
DWORD color;
};

CUSTOMVERTEX g_Vertices[] =
{
{ -1.0f,-1.0f, 0.0f, 1.0f, 0xffff0000, },
{ 1.0f,-1.0f, 0.0f, 1.0f, 0xff0000ff, },
{ 0.0f, 1.0f, 0.0f, 1.0f, 0xffffffff, },
};

g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
0,
D3DFVF_XYZRHW|D3DFVF_DIFFUSE,
D3DPOOL_DEFAULT,
&g_pVB ) );

VOID* pVertices;
g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 ) ) ;
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
g_pVB->Unlock();

g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetVertexShader( D3DFVF_XYZRHW|D3DFVF_DIFFUSE);
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );



Would you please tell me what's the problems about the first seagment code~{#?~}
Thank you very very much!

P.S.
The D3D I used is D3D8.

Best Regards!
Opalm
30/07/2004

Edited by Coder: source tags

[Edited by - Coder on July 30, 2004 6:42:56 AM]

Share this post


Link to post
Share on other sites
Muhammad Haggag    1358
Quote:
Original post by Opalm
HI,

I have a question about D3D, FVF rendering~{!#~}

I have try to use the following code,
*** Source Snippet Removed ***

it dose not work correctly, but when I use following code it
work correctly.
*** Source Snippet Removed ***


Would you please tell me what's the problems about the first seagment code~{#?~}
Thank you very very much!

P.S.
The D3D I used is D3D8.

Best Regards!
Opalm
30/07/2004

Edited by Coder: source tags

You'd better create a new thread for your new question.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this