Sign in to follow this  

What would you normally do if you have 2 sets of APIs to call upon?

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

If I have both OpenGL and DirectX

do you do something like this

 

#if OPENGL

glMatrix GetViewMatrix()

#else

D3DXMATRIX GetViewMatrix()

#endif

{

}

 

if I have hundreds of these methods/functions, it would be quite tedious to code.

What is the general practices of this?

Thanks

Jack

Share this post


Link to post
Share on other sites
For this example, you would probably want a typedef or a struct containing the matrix. You should be able to have a basic math header that defines inline functions amd typedefs for their arguments and return values.

Share this post


Link to post
Share on other sites
What he said ^
//write once:
#if OPENGL
typedef glMatrix GfxMatrix;
#else
typedef D3DXMATRIX GfxMatrix;
#endif
...
//many uses:
GfxMatrix GetViewMatrix();
 
But in this particular case, just use the same matrix structure in both versions of the code. If you need conversion functions internally, then write them.
struct GfxMatrix {};

D3DXMATRIX Cast( const GfxMatrix& ) {...}
glMatrix   Cast( const GfxMatrix& ) {...}

//or: this may be valid if you can ensure your class and the one you're mapping to use the exact same memory layout
const D3DXMATRIX& Cast( const GfxMatrix& mat ) { return *(D3DXMATRIX*)&mat; }
However, neither D3D or GL require you to use some specific matrix type. They both accept float[16] at the lowest level... You're talking about using some "glMatrix" type (not part of OpenGL, what is this library?) and also using D3DX. You  can just pick one of those libraries and use it for both GL and D3D! Edited by Hodgman

Share this post


Link to post
Share on other sites

 

However, neither D3D or GL require you to use some specific matrix type. They both accept float[16] at the lowest level... You're talking about using some "glMatrix" type (not part of OpenGL, what is this library?) and also using D3DX. You can just pick one of those libraries and use it for both GL and D3D!

 

 

Going further with that, you should use a pre-built math library to help you that is cross-platform in order for it to be used with GL and D3D. I recommend glm.

Share this post


Link to post
Share on other sites

This topic is 1605 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this