Sign in to follow this  
Xtremehobo

Something wrong with the format of my FVF?

Recommended Posts

Xtremehobo    820
I'm having some issues getting a simple triangle to render w/ Direct3D9. Culling is off and I'm using one backbuffer. I've checked over my code and read the debug info D3D is giving me and I can't seem to find anything wrong with my code so Im assuming something might be wrong with my FVF. I've had issues in the past before where I've changed my FVF and all of a sudden something rendered, however this time, my setup isn't going to work correctly with a different FVF. Anyways, my FVF:
typedef struct{
    FLOAT x, y, z;   
    FLOAT nx,ny,nz;
    DWORD color;
    FLOAT tu, tv;    // The texture coordinates
} CUSTOMVERTEX;


#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1)

I've copied the data into a vertex buffer and just to make sure it copied correctly I've locked the VB and copied the data back into a CUSTOMVERTEX array and the values were fine.
CUSTOMVERTEX v;
	v.x=150;
	v.y=50;
	v.z=1;
	v.nx=0;
	v.ny=0;
	v.nz=-1;
	v.color=0xffffffff;
	v.tu=0;
	v.tv=1;
	CUSTOMVERTEX v2;
	v2.x=250;
	v2.y=250;
	v2.z=1;
	v2.nx=0;
	v2.ny=0;
	v2.nz=-1;
	v2.color=0xffffffff;
	v2.tu=1;
	v2.tv=1;
	CUSTOMVERTEX v3;
	v3.x=50;
	v3.y=250;
	v3.z=1;
	v3.nx=0;
	v3.ny=0;
	v3.nz=-1;
	v3.color=0xffffffff;
	v3.tu=1;
	v3.tv=0;

	CUSTOMVERTEX vx[3];
	vx[0]=v;
	vx[1]=v2;
	vx[2]=v3;



		void* pVertices;
		vertexbuffers[currentface].vb->Lock( 0, 0, (void**)&pVertices, 0 );
		//memcpy(pVertices, &vertices[currentface].vertices, sizeof(CUSTOMVERTEX)*face.polycount*3);
		memcpy(pVertices, vx, sizeof(CUSTOMVERTEX)*face.polycount*3);

		vertexbuffers[currentface].vb->Unlock();
		
// Double check the VB.
		CUSTOMVERTEX vxx[3];
		vertexbuffers[currentface].vb->Lock(0, 0, (void**)&pVertices,0);
		memcpy(vxx,pVertices,sizeof(CUSTOMVERTEX)*3);
		vertexbuffers[currentface].vb->Unlock();

Is there an obvious mistake here or is it more likely that the problem lies elsewhere? Thanks!

Share this post


Link to post
Share on other sites
Pipo DeClown    804
Aren't FVFs old? I thought they got replaced by Vertex Declarations..

Quote:
Vertex Decleration

A vertex declaration defines the vertex buffer layout and programs the tessellation engine. Starting with Microsoft DirectX 9.0, vertex streams are expressed as an array of D3DVERTEXELEMENT9 structures (instead of using flexible vertex format (FVF) codes). Each array element describes each per-vertex data type. Converting FVF codes into the new format is covered in the following topics:

-Mapping FVF Codes to a DirectX 9 Declaration
-Fixed Function FVF Codes
-Mapping between a DirectX 9 Declaration and FVF Codes
-Mapping between a DirectX 9 Declaration and a DirectX 8 -Declaration
-Programming One or More Streams

Share this post


Link to post
Share on other sites
Xtremehobo    820
I changed it to use Vertex Declarations now, still doesn't render anything.

LPDIRECT3DVERTEXDECLARATION9 pVertexDeclaration;
D3DVERTEXELEMENT9 dwDecl[] =
{
// Stream Offset Type Method Usage Usage Index
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, sizeof(float)*3, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{ 0, sizeof(float)*3*2, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, sizeof(float)*3*2+sizeof(DWORD), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};

pd3dDevice->CreateVertexDeclaration( dwDecl, &pVertexDeclaration );

pd3dDevice->SetVertexDeclaration(pVertexDeclaration);




pd3dDevice->SetStreamSource( 0, vertexbuffers[0].vb, 0, sizeof(CUSTOMVERTEX));

pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );

Share this post


Link to post
Share on other sites
Raloth    379
You shouldn't have to change to vertex declarations.

Where do you call Draw*Primitive?

(And I would suggest changing that define to a const DWORD, it's cleaner.)

Share this post


Link to post
Share on other sites
Xtremehobo    820
Quote:
Original post by Raloth

Where do you call Draw*Primitive?


shown in the above code.

Also, I don't think I'll be keeping the vertex declarations seeing as how they're not working either so that must not be where the problem is. I'd like to use FVF If I can make it work.

Share this post


Link to post
Share on other sites
Domini    126
Can you post a little more info, like you FVF rendering implementation? Ie, are you calling SetFVF()?(I think that's the method) If you have multiple vertex formats, are you calling SetFVF when you switch to this one. I only use shaders and VertexDeclarations, so I'm a little rusty on DX9 and FVF. Wish I could help more.

Is the screen completely black? If nothing is rendering it could be something else. Check the return value of your DrawPrimitive()?

Share this post


Link to post
Share on other sites
Samurai Jack    455
Salutation young friend!

There is more to Rendering than just the vertex data:

1. Maybe you don't have a vertex buffer at all? check if valid, means != NULL
2. If the buffer exists, verify the PROJECTION, VIEW & WORLD matrix
3. If all that is correct, try to change CLEAR COLOR to RED or BLUE, not black, it is possible, that the vertex buffer is rendered black on a black background and you see nothing
4. Are the lights enabled?
5. Which material is set to default? BLACK?
6. Is the texture missing or used NULL ?

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