1

I studied the manual for DirectX 9 and DirectX 11 and C++ was used there, I was wondering if there is DirectX support in C?

I have studied C well enough and I want to try to write a small renderer on it. I don't really like OpenGL, DirectX is much more attractive to me.

IlyagDev
  • 35
  • 3
  • Does this answer your question? https://stackoverflow.com/questions/4696079/directx-programming-in-c It happens to be the first hit in my favorite search engine for the promising search term "directx c". – Yunnosch Jul 04 '23 at 12:05
  • Does this answer your question? [How to interact with COM objects using C?](https://stackoverflow.com/questions/9148128/how-to-interact-with-com-objects-using-c) – Simon Mourier Jul 04 '23 at 13:49
  • @SimonMourier I do not see the connection. What did I miss? – Yunnosch Jul 04 '23 at 14:57
  • @Yunnosch - DirectX is based on COM (not the whole COM, but it uses the vtable etc.) https://learn.microsoft.com/en-us/windows/win32/prog-dx-with-com and Microsoft's SDK ships with macro to call it using C – Simon Mourier Jul 04 '23 at 15:22
  • @SimonMourier Thanks, that is a good explanation why you propose a COM question as duplicate. – Yunnosch Jul 04 '23 at 18:03

1 Answers1

2

You can use DirectX COM interfaces from C, but the experience is generally unpleasant as it requires a lot of macros. COM interfaces map well to C++ abstract classes and single-inheritance hierarchies. It's also not well-tested as basically all users of DirectX use C++ and not C. The support that is there is basically whatever legacy behavior the MIDL compiler throws in there for C.

You don't need to know much modern C++ to use them, so you could consider just using "C++ as a better C" for your code, and then take advantage of the more natural COM interface behavior.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81