Jump to content
  • Advertisement
Sign in to follow this  
jbb

OpenGL Dynamically loading and unloading of directx

This topic is 2784 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'm working on a small game project where I want to be able to use d3d11 but to fall back to d3d9 if it's not available / installed.

I can abstract out the drawing interface so that my game with work with either, but if I have to link with the d3d11 DLLs then my program won't even load if they are missing.

So I thought the best thing to do was to use LoadLibrary and GetProcAddress to load the d3d9.dll and locate the "Direct3DCreate9" function, and to do similar for D3D11 and just use whichever loaded. (I'm fully aware they are not very similar and will need a considerable amount of abstraction to present the same interface to my game).

My question though, is are there any problems with loading directx dynamically like this? And if I shut down the directx device can I safely unload the DLLs should I wish to?

I'd ideally like to do the same with opengl as well, although that seems more painful as there are hundreds of entry points to use GetProcAddress on so I might leave that out.

My question though is as above - can I safely load d3d9 and d3d11 dynamically, and can I unload the DLLs when I'm finished with them? A quick check seems to indicate that I can load the sucessfully and use them, but perhaps there is something I'm unaware of.

Share this post


Link to post
Share on other sites
Advertisement
With OpenGL you're required to load most newer functionality dynamically, as only version 1.1 (I think) is in OpenGL32.dll, and for the later ones you need to use wglGetProcAddress with an active context instead. There are multiple free libraries that do this for you, among other things, for example GLEW.

An alternative to LoadLibrary is Delay-Loaded DLLs, but either method should work fine. You can unload a library with FreeLibrary if you're not using it anymore.

One problem with dynamically loading D3D can be that the user has an earlier version of a DirectX DLL installed than the one you use when you build your program, for example D3D11.dll from August 2008 while you build with the one from June 2010. This could potentially lead to things not working exactly the way you expect, which is why it is a better idea to include the DX redistributable installer with your game instead, if possible.

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!