Jump to content
  • Advertisement
Sign in to follow this  
Game_XinBing

About D3DVERTEXELEMENT9?

This topic is 3335 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 declare D3DVERTEXELEMENT9 decl[]={{...},{...},D3DDECL_END()}; in my new custom class(example CMyMesh). But, in .h file, it's incorrect. How can i do to delcare it as a member variable of CMyMesh class? Thank you!

Share this post


Link to post
Share on other sites
Advertisement
You're probably trying to declare and initialise the array in the class header, which you can't do. You'll need to declare it in the header, then fill in each element in the constructor. Or use a std::vector<D3DVERTEXELEMENT9> and populate that in the constructor.

If that doesn't work, we'll need to know the exact error you get, and we'll need to see your source.

Share this post


Link to post
Share on other sites
You'll need to declare it in the header, then fill in each element in the constructor.
=================================================================
Thank you. it right.
But i think D3DVERTEXELEMENT9 decl[] is different from Array,
because it has a tail D3DDECL_END().
So, How can i declare it in .h file and How can i initial it
in .cpp file's Constructor.
Thank you very mush.

Share this post


Link to post
Share on other sites
If i correct understand your question you want something like:


class cMyClass
{
private:
D3DVERTEXELEMENT9 decl[] = {...};
};



than you can't C++ syntax forbid this.

Use vector<D3DVERTEXELEMENT9> as was sugested before and initialize it in constructor or some other function.

Share this post


Link to post
Share on other sites
Quote:
Original post by Game_XinBing
But i think D3DVERTEXELEMENT9 decl[] is different from Array,
because it has a tail D3DDECL_END().

Nope, it's just a normal array of structs. D3DDECL_END() just gives you a value that you need at the end of this array.

Quote:

So, How can i declare it in .h file and How can i initial it
in .cpp file's Constructor.


You could do this:


// in header
class C {
std::vector<D3DVERTEXELEMENT9> decls;
};

// in source file
C::C() {
const D3DVERTEXELEMENT9 tempDecl[] = { // demo declaration only!
{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()
};

size_t tempDeclSize = sizeof(tempDecl) / sizeof(*tempDecl);
decls.insert(decls.begin(), tempDecl, tempDecl + tempDeclSize);
}


Share this post


Link to post
Share on other sites
You don't need a vector. You probably want this static anyway, so define it in the class

class C
{
static D3DVERTEXELEMENT9 decl[];
}

And in your source file

D3DVERTEXELEMENT9 C::decl[] = { ... }

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!