# Vertex FVF classes... static members?

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

## Recommended Posts

Ok, if I create a series of classes for my vertex data, like Simplevertex, VertexTextureColorNormal etc, would I be able to place a static variable in the class with the value for the FVF?
struct SimpleVertex
{
static long FVF = fvf values;
float x,y,z;
float nx,ny,nz;
float r,g,b,a;
};

or does that screw up the data during buffering? It would be really nice to just use SimpleVertex::FVF where I needed the FVF for the class.

##### Share on other sites
You will be OK doing that.
I would stick to the SDK data type for an FVF though, which is DWORD (AFAIK unsigned long).

***edit***
The static FVF is OK but the rest of your vertex structure looks wrong.

float x, y, z is ok for the vertex position.
float nx, ny, nz is ok for the normal.

not sure about the color data though (r,g, b, a) as floats.
I think the color data type should be D3DCOLOR (DWORD)

Also I think the ordering of the (non static) structure members should be different.

Try this:

struct SimpleVertex
{
float x, y, z; // position
D3DCOLOR diffuse; // diffuse color
float nx, ny, nz; // normal
static DWORD FVF;
};

DWORD SimpleVertex::FVF = D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_NORMAL;

Also you can set the r, g, b, a values for the color using the D3DCOLOR_RGBA macro:

v.diffuse = D3DCOLOR_RGBA(r,g,b,a);

r, g, b,a values here should be between 0 and 255.

HTH,
Cambo_frog

[Edited by - Cambo_frog on July 30, 2005 3:07:53 PM]

##### Share on other sites
The note on diffuse is correct - it's a DWORD, too. However, normals do come before diffuse when using FVF buffers.

##### Share on other sites
I wasn't so much concerned with the datatypes, because I still have to look those up for every vertex definition. But thanks anyways!