Jump to content
  • Advertisement
Sign in to follow this  
Shawn1984

Vertex format in the .x file

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

I want to write a shader program to display a model. But I found that I can't know what exactly the vertex format is in a .x file. Althought there is a function GetFVF but I can't know what kind of combination it is.Could anyone share some information? Thanks a lot in advance!

Share this post


Link to post
Share on other sites
Advertisement
You can work out the vertex structure from the FVF. E.g. if the FVF is D3DFVF_XYZ | D3DFVF_TEX1, then you know there's a position (3 floats) and one set of texture coordinates (2 floats). And since you know the order the components have to be in (It's documented in the SDK help somewhere), you can work out the vertex structure.

Share this post


Link to post
Share on other sites
The best thing to do is to clone the mesh into the format your shader expects. That way you can load the various .x files that come with the SDK and render them. For some, you will need to have DX create the normals. Here is how I check the .x file for normals and texture coordinates:

D3DVERTEXELEMENT9 elems[MAX_FVF_DECL_SIZE];
BOOL hasNormals = FALSE;
BOOL hasTexCoords = FALSE;
hr = ObjectMesh->GetDeclaration(elems);
if (SUCCEEDED(hr))
{
for(int i = 0; i < MAX_FVF_DECL_SIZE; ++i)
{
// Did we reach D3DDECL_END() {0xFF,0,D3DDECLTYPE_UNUSED, 0,0,0}?
if(elems.Stream == 0xff)
break;

if( elems.Type == D3DDECLTYPE_FLOAT3 &&
elems.Usage == D3DDECLUSAGE_NORMAL &&
elems.UsageIndex == 0 )
{
hasNormals = TRUE;
}
if( elems.Type == D3DDECLTYPE_FLOAT2 &&
elems.Usage == D3DDECLUSAGE_TEXCOORD &&
elems.UsageIndex == 0 )
{
hasTexCoords = TRUE;
}
}
}


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!