How to fill in D3DVERTEXELEMENT9 structure?
Quote:Original post by Trip99
Are you using the D3DX mesh? If so you can use the clone op
No, the VB and IB are on their own, not in a mesh.
To define your vertex declaration, you have to create an array of D3DVERTEXELEMENT9 structures. D3DVERTEXELEMENT9 is defined as:
You can find a list of D3DDECLTYPEs here. The most commonly used ones are float1, float2, float3, float4, and D3DCOLOR.
You can find a list of D3DDECLUSAGEs here. Commonly used ones are POSITION, NORMAL, TEXCOORD, and TANGENT.
An declaration of D3DVERTEXELEMENT9s usually goes like this:
This specific declaration has 3 elements:
float3 POSITION
float3 NORMAL
float2 TEXCOORD
Once you have your array of D3DVERTEXELEMENT9s, you need to create an IDirect3DVertexDeclaration9. The good thing is, this is easy:
.
That's it! Now, you can create your vertex buffers and everything like that. We only need to do one more thing - before rendering the VB, we have to set the appropriate vertex declaration. This way, Direct3D knows what format our vertex buffer is in.
And that is all it takes [wink]
D3DVERTEXELEMENT9 { WORD Stream; // This is the stream this element resides in WORD Offset; // Offset from the beginning of the vertex data. Get this by adding up the size of the types defined before this element. BYTE Type; // The data type (ie D3DDECLTYPE_FLOAT3) BYTE Method; // Use D3DDECLMETHOD_DEFAULT here BYTE Usage; // Defines what the data will be used for (this is the semantic in your shader - ie D3DDECLUSAGE_POSITION) BYTE UsageIndex; // Modifies the usage data to allow the user to specify multiple usage types.}
You can find a list of D3DDECLTYPEs here. The most commonly used ones are float1, float2, float3, float4, and D3DCOLOR.
You can find a list of D3DDECLUSAGEs here. Commonly used ones are POSITION, NORMAL, TEXCOORD, and TANGENT.
An declaration of D3DVERTEXELEMENT9s usually goes like this:
D3DVERTEXELEMENT9 simple_decl[] ={ {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END() // this macro is needed as the last item!};
This specific declaration has 3 elements:
float3 POSITION
float3 NORMAL
float2 TEXCOORD
Once you have your array of D3DVERTEXELEMENT9s, you need to create an IDirect3DVertexDeclaration9. The good thing is, this is easy:
// d3dDevice is your LPDIRECT3DDEVICE9// simpleDecl is the array of D3DVERTEXELEMENT9s we defined aboveIDirect3DVertexDeclaration9* myVertexDecl;d3dDevice->CreateVertexDeclaration(simple_decl, &myVertexDecl);
That's it! Now, you can create your vertex buffers and everything like that. We only need to do one more thing - before rendering the VB, we have to set the appropriate vertex declaration. This way, Direct3D knows what format our vertex buffer is in.
// d3dDevice is your LPDIRECT3DDEVICE9// myVertexDecl is the LPDIRECT3DVERTEXDECLARATION9 that we defined aboved3dDevice->SetVertexDeclaration( myVertexDecl );// You are now ready to go!// Set all your stream sources, and DrawIndexedPrimitive()
And that is all it takes [wink]
Quote:Original post by Alex Swinney
How does one go about filling this structure in to create a mesh?
You don't create a mesh out of D3DVERTEXELEMENT9s, it just describes the contents of the VB (or in the case of streams, all the VBs).
Quote:Original post by NamethatnobodyelsetookQuote:Original post by Alex Swinney
How does one go about filling this structure in to create a mesh?
You don't create a mesh out of D3DVERTEXELEMENT9s, it just describes the contents of the VB (or in the case of streams, all the VBs).
Yes, but it is needed in order to create a mesh, and that was the point;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement