Jump to content
  • Advertisement
Sign in to follow this  
Eddie Zehoo

Weird Problem with SetFVF

This topic is 5101 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

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
Advertisement
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
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
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!