Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

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

This topic is 1825 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
Advertisement

my preferred way to do it is to have 2 static libs implementing the abstractions. The build system will link the appropriate lib for the platform.

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
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!