4
\$\begingroup\$

I thought that if you wanted to make games using DirectX, you had to know C++. But I recently found out that that is not actually true. It looks like some parts of Direct3D can be used from C#. This MSDN document, for example, which has C# examples.

Am I understanding this incorrectly? Have I waited all these years for nothing?

\$\endgroup\$
0

2 Answers 2

8
\$\begingroup\$

Yes, there are DirectX bindings for C#. This has been available for almost 10 years or more.

XNA (announced 2004), MonoGame (announced 2009), SharpDX and more all provide you the ability to access DirectX using C#. You actually only need to Google "C# DirectX" and you'll find plenty resources on this. The MSDN documents you are link to in your question, however, are referencing Microsoft's own "Managed DirectX," which is now deprecated and not a viable choice for new development.

Additionally, you only need to look a little further into link you provided to find sample projects you can use with the Direct3D API.

\$\endgroup\$
8
  • \$\begingroup\$ Okay thanks I got that. But that is not exactly answers my question. When I see the Direct3D c# examples I thought I can use Direct3D in my C# projects without using any third party library like SharpDX. \$\endgroup\$ Commented Sep 29, 2013 at 15:50
  • 1
    \$\begingroup\$ I'd say SharpDX is the closest to what is being asked. XNA and MonoGame do not allow the user to directly call DirectX, as far as I know. \$\endgroup\$
    – luiscubal
    Commented Sep 29, 2013 at 15:50
  • \$\begingroup\$ I was making it clear that there is plenty of evidence to the contrary of "I thought if you want to make games using DirectX , you had to know C++". I've updated the answer to include a link to the Direct3D API where you can get some sample projects. \$\endgroup\$
    – House
    Commented Sep 29, 2013 at 15:56
  • 2
    \$\begingroup\$ @SemihMasat Those MSDN pages you linked to are old, and refer to Microsoft's "Managed DirectX," which is deprecated and no longer viable for use. All it did was exactly the same thing SlimDX or SharpDX do anyway: provide P/Invoke-based or C++/CLI-based wrapper bindings for the C or C++ DirectX APIs. \$\endgroup\$
    – user1430
    Commented Sep 29, 2013 at 15:59
  • \$\begingroup\$ Thank you. I know I sound like complete noob. But when ask people, they always said, "no you cannot use directX with c#" . But looks like I can use Direct3D API. Maybe I am understanding this all wrong. \$\endgroup\$ Commented Sep 29, 2013 at 16:05
2
\$\begingroup\$

In 2023, this question is still one of the most prominent search engine results when typing "DirectX C#". Therefore, here is a renovated answer:

Since 2013, the answers to that question have been coming and going.

Here is a little guided tour:

1. Wrapper libraries

DirectX is designed to be programmed in C++, so for a decade some people have attempted to write interop libraries and wrappers to use it in C#.

You can find several of those libraries with search engines, the most recent being mostly targeted at Visual Studio 2017 and DirectX11.

Some examples :

The problem is that those were mostly projects working "around" DirectX's official development effort, the support can be limited. SharpDX was very promising but the support stopped in 2019.

2. Mono

For some time, Microsoft has pushed Mono to make games. That's not exactly directX (I didn't research it but I bet it does rely on it, though) however it's definitely made for cross-platform, high-performance (accelerated) graphical applications. In a way, you could say that it is "better" than DirectX.

the problem is that Mono has stalled and in 2023 is no longer bleeding edge.

3. Unity

Unity lets you work directly in C#. And lets you make fully-fledged high-performance, interactive graphical applications. Just like Mono, it's an advanced engine on top of DirectX. And an IDE on top of the engine.

I guess that Unity's very existence it's telling you that the industry is moving away from accessing DirectX "directly" (unless you can program in C++, obviously) and instead use a "real" environment. Game development has become so complex that there's no in-between offer anymore.

3bis. Unreal Engine?

I don't know if there are C# wrappers around Unreal Engine but I wouldn't be surprised. Just like Unity it's much, much more than "just" DirectX so it's up to you to decide if it's "too much" depending on your needs.

4. ComputeSharp

But do not despair! ComputeSharp is a production-ready C# library meant to use the GPU mostly for computing. It's modern, well-maintained, well documented.

It's designed for computing BUT their Sample applications show you how to interop with WinUI, UWP and others (so that you can draw pixels onto the screen). Plus, it lets you access any underlying DirectX resource that you might need thanks to special binders -- those require a tiny bit of effort because you need to switch your brain to "C++ mode" even if you're still in C#. Just go along with it. Read the documentation, you should be fine.

So in some places it resembles C++ very much (again: even in your C# code) but you can still fully benefit from C# -- especially in the shaders, which is awesome.

CONCLUSION

I don't know exactly what was the intent of the original poster's question.

Butin 2023 if YOUR goal is to use the GPU, draw pixels onto the screen and write a "regular" graphical application on Windows (with sound, input/output, etc.) without relying on the absolute monster that is Unity, then I'd go for ComputeSharp.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .