Jump to content
  • Advertisement
Sign in to follow this  

Help explaining these d3d vertex definition structs

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

Hi, I need help using the direct3d vertex definitions found at http://www.mvps.org/directx/articles/definitions_for_dx7_vertex_types.htm I'm working with pre dx8 code, and need a bit of help understanding the code on that page. A few questions: 1.
typedef struct _D3DVERTEX {

Why is the struct name prefixed with an underscore? 2.
    _D3DLVERTEX() { }
    _D3DLVERTEX(const D3DVECTOR& v,D3DCOLOR col,D3DCOLOR spec,float _tu, float _tv)
        { x = v.x; y = v.y; z = v.z;
          color = col; specular = spec;
          tu = _tu; tv = _tv;

what does that code do? I've got the code from that page in a header file, but i'm getting compile errors regarding the code I pasted above in question #2 Namely: (regarding the first line) Error 1 error C2061: syntax error : identifier '_D3DLVERTEX' (both regarding the second line) Error 2 error C2143: syntax error : missing ')' before '&' Error 4 error C2059: syntax error : '&' I've seen another example of this code where the person surrounded this code in a conditional block, and changed a few things around.
#if (defined __cplusplus) && (defined D3D_OVERLOADS)
    _D3DTLVERTEX() { }
    _D3DTLVERTEX(const D3DVECTOR& v, float _rhw,
                 D3DCOLOR _color, D3DCOLOR _specular,
                 float _tu, float _tv)
        { sx = v.x; sy = v.y; sz = v.z; rhw = _rhw;
          color = _color; specular = _specular;
          tu = _tu; tv = _tv;

I'm using these vertex defitions from a C++ file so i'm assuming that code will be compiled regardless? If anyone could shed some light, i'd really appreciate it :)

Share this post

Link to post
Share on other sites
1. The C++ (and I think C) standard(s) state(s) that anything with a leading underscore is reserved for implementation use. More specifically, the directX API used an underscore because they planned on typedefing that struct into probably two types: a pointer to that structure and the structure itself. I bet at the end of the structure they have something like line:
} D3DVertex, *LPD3DVertex;

2. The first line is the default constructor of the struct. This constructor does nothing. They create a default constructor because the standard says that if you create a non-default constructor the compiler will not generate one automatically any more.

The second line onwards is the constructor that you call when you want to fill in all the listed values. Basically, DirectX is using classes in all but name.

Your unasked 3rd question: You probably have an error before the error that is listed by the compiler. Post a few lines before that one in your actual code and we may be able to help.

Share this post

Link to post
Share on other sites
I thiink I got it sorted, copied and pasted the code again (I need to change a few values from that, must have left something out before..)

The information was invaluable to me though, so thanks :) I hate working with code I don't understand!

And you're right, there is a "} D3DVertex, *LPD3DVertex;"

I'll post back if I have any other issues with it later, but it seems to be ok now :)

Thanks again!

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!