Nope. OpenGL calls treat an D3DDXVECTOR3 just like an array. So the following are equivalent:
D3DXVECTOR3 V(0.0f, 0.0f, 0.0f);
float A[3] = {0.0f, 0.0f, 0.0f);
glVertex3fv(V);
glVertex3fv(A);
The specification for most of the "fv" OpenGL commands is:
void glVertex3fv( const GLfloat *v )
So I guess the D3D vectors have some funky templating or operator overloading to make them function exactly as vanilla C arrays when passed around?
You can also use them in this way to, but leave the "v" off the command:
D3DXVECTOR3 V(0.0f, 0.0f, 0.0f);
glVertex3f(V.x, V.y, V.z);
OpenGL Vector (coming from DirectX)
Quote:Original post by FippyDarkpawInteresting - I didn't know about that...
Nope. OpenGL calls treat an D3DDXVECTOR3 just like an array. So the following are equivalent:
D3DXVECTOR3 V(0.0f, 0.0f, 0.0f);
float A[3] = {0.0f, 0.0f, 0.0f);
glVertex3fv(V);
glVertex3fv(A);
The specification for most of the "fv" OpenGL commands is:
void glVertex3fv( const GLfloat *v )
So I guess the D3D vectors have some funky templating or operator overloading to make them function exactly as vanilla C arrays when passed around?
I have started to write a D3DX clone for my OpenGL project.
Maybe it can help some people.
It's not optimized and finished, but it could be usefull for small projects.
it's under a BSD-style license.
http://texel3d.free.fr/projets/glgx/index.html
Maybe it can help some people.
It's not optimized and finished, but it could be usefull for small projects.
it's under a BSD-style license.
http://texel3d.free.fr/projets/glgx/index.html
Quote:Original post by FippyDarkpaw
So I guess the D3D vectors have some funky templating or operator overloading to make them function exactly as vanilla C arrays when passed around?
Nothing funky about it.
operator float*() {return &x}
Or T* for a template class. Can make OpenGL code so much nicer to look at.
Just add a cast operator and the compiler can figure out when to use it on its own. Unless you start going overboard with tons of casting operators and start confusing the compiler (being forced to use explicit casts to fix that kind of defeats the purpose).
Unless I'm missing something, you can rely on
float x,y,z;
to always end up exactly like that in memory (ie. just like float c[3]). Just don't mix different types or their alignment might bite you (rule of thumb: declare members from largest to smallest to minimize the objects size in memory, for example char x; float y; will waste 3bytes).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement