1

the guy that asks weird things, here, again

I see that they use different executables, for a game that was created for both directx 9 and 10. It is possible to include "d3d9.h" and "d3d10.h" in a code file, then select direct3d 9 functions or direct3d 10 functions, depending on, for example, an argument that acts like a flag? I am not talking about drawing something using a direct3d 10 function using a direct3d 9 context and object.

What I want to do is create a function called init3D(UINT version); Depending on version, it will create a directx 9 or directx 10 object and device. I don't know if that is possible or I must create two different executables (or 3 if I decide to use d3d8, too)

Thanks for your help and forgive my lack of understanding with some of the C++ techniques.

ali
  • 10,927
  • 20
  • 89
  • 138

3 Answers3

1

Yes it's entirely possible.

The only issue is that the libraries for both must exist on the target machine. Because you've linked with d3d10 it must be installed on the machine for your .exe to even load even if you want to run in d3d9 mode, and that won't be the case on xp machines.

To avoid this you'll need to use dynamic linking to call any functions so that the libraries are only loaded at run time. Look up LoadLibrary and GetProcAddress. Luckily with direct3d the only global functions you'll likely call are the "create" functions. D3DX will cause the same issues though

jcoder
  • 29,554
  • 19
  • 87
  • 130
  • Run-time linking isn't a bit slower? – ali Jul 02 '12 at 13:12
  • Not really, some tiny overhead calling through a function pointer instead of directly. The alternative is to put your d3d9 and d3d10 code into separate dlls and then only load one of them at run time. – jcoder Jul 02 '12 at 13:55
1

You do understand that DirectX 8 is not supported right? DirectX 10 includes DirectX 9 so there isn't a reason to require both.

You should be able to conditionally include the header files based on what version of DirectX is installed.

Here is an example of how to do exactly that although its written in C#:

How to code to get direct X version on my machine in C#?

The traditional way is install the version of DirectX your application uses when your application is installed. Any other way should be considered a hack and unsupportable in the long-term.

Community
  • 1
  • 1
Security Hound
  • 2,577
  • 3
  • 25
  • 42
  • I will create two version of the executable, one for those systems that don't support directx 10 and another for those supporting directx 9 and 10. – ali Jul 02 '12 at 13:15
  • Does DirectX 10 includes DirectX 9? So, if I create an application with d3d10.lib/d3d10.h will I be able to run it on a Windows 7, for example, with DirectX9.0c? – ali Jul 02 '12 at 13:16
1

One other comment. What platform do you want to run this on?

Windows vista and newer will run directx11 and directx11 will work on directx9 level hardware (obviously without the newer features like tessalation shaders).

If you don't need to support XP (and it really is getting quite old now...) then forget both dx9 and dx10 and just use directx11

jcoder
  • 29,554
  • 19
  • 87
  • 130