Comparison between XNA and DirectX (C#)

C#DirectxXna

C# Problem Overview


In terms of PC development (excluding Xbox and Zune),

What is the difference between XNA and C# DirectX? Does C# DirectX have a significant advantage over XNA (in terms of speed, royalties, etc)?

How are the two compared to the speed unmanaged C++ DirectX?

Where is the industry moving in terms of game programming?

C# Solutions


Solution 1 - C#

If you're actually good at writing unmanaged code, then you'll probably be able to write a faster graphics engine on top of DirectX. However, for the hobbyist, XNA has plenty of performance, both for 2D and 3D game development.

Here is a good Channel 9 video where they run an XNA-built racing game on Xbox 360. It runs well even at full HD. Several of the XBox Live Arcade games have been developed by the XNA community.

As far as C# DirectX, as I recall, Managed DirectX as it was called, is no longer officially supported since XNA basically replaces it. I could be wrong, its been a very long time since I looked at it.

The performance differences are negligible between XNA and Managed DirectX since, in essence they're the same thing; XNA just has a few convenience bits to reduce the amount of boilerplate code you need to write.

Solution 2 - C#

The Xna Game Studio stuff is focused around solving game centric problems, though I would question any poster that says the performance of the Xna game studio stuff is any worse than managed direct x without seeing some decent metrics.

An independent group outside of MS have created a project called SlimDx - http://slimdx.mdxinfo.com/ If you are writing an application rather than a game (which I expect you are not by the other questions) then that might be worth considering.

The industry still heavily uses C++ for game guts, but there have been successful releases of games written in completely managed code using XNA Game Studio on the community games section of XBox live, and released on the XBox Arcade itself. There should be some interesting stats coming pretty soon about how much people have made on the community games.

Many full price games use C++ for some, but something like Lua for actual game logic... and Lua is not known for the blazing speed!

C# has a good learning curve and is used by tools programmers in the industry - it would be a useful language to have under your belt. C++ would be a great language to have, but it requires more discipline to create functional code - and gives someone new a lot more rope to hang themselves by. C# can dynamically change and do things like unroll loops at runtime rather than compile time - good C# can be as fast or faster than good readable C++ - but you have to know how to use it. In really tight loops, C++ and Assembler might win out in certain circumstances. Often in games using C++, custom allocators are created with their own memory strategies to try and help fragmentation caused by normal allocators... that kind of thing is dealt with by the CLR in .Net/C# and as long as you program to the garbage collectors strengths (the same that you would have to do with your own C++ implementation) then you do not have to concern yourself with such low level implementation detail in .Net.

If you are looking in to getting in to game development and deciding on a language (which, reading between the lines seems to be where you are going with that line of questioning) then the best language to use is the one where you have a finished project to show at the end of it, be it C++, objective C, C#, Flash, Silverlight, etc. As languages change and go in and out of favour, recruiters often look for proven mastery of different languages - which might mitigate not knowing the one they are currently using - and a portfolio of completed work would do that.

Solution 3 - C#

  1. XNA and DirectX are very different implementations to solve the same problem - high performance graphic intensive programming. Both support 2D, 3D, audio and networking components. DirectX is unmanaged only where XNA is managed code.
  2. There is a managed implementation of DirectX which is a wrapper around the DirectX calls but that is not getting updated after the current release so I wouldn't bother with it.
  3. XNA is not a wrapper around unmanaged DirectX. It does use parts of DirectX but it is not a wrapper.
  4. The industry still seems very much set on unmanaged DirectX - I say that because all the major engine companies are still coding in C++, ASM and supporting DirectX (either solely or in conjunction with OpenGL for Linux/Mac versions). The fact Microsoft is "dropping" the DirectX managed wrapper and telling people to rather use XNA shows that is where they are pushing managed developers.

Solution 4 - C#

At the moment, it seems that Microsoft do not plan to support XNA in Metro style apps. An alternative to XNA and the now deprecated "Managed DirectX" is SharpDx. This can be used to create Metro style apps and has been favourably benchmarked against XNA, SlimDX and the windows API code pack.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionworbelView Question on Stackoverflow
Solution 1 - C#SoviutView Answer on Stackoverflow
Solution 2 - C#paulecoyoteView Answer on Stackoverflow
Solution 3 - C#Robert MacLeanView Answer on Stackoverflow
Solution 4 - C#Dave MaffView Answer on Stackoverflow