• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
147

DirectX11 which programming language?

25 posts in this topic

As the topic title indicates, I want to know which programming language is best for programming DirectX11? I know, that C++ in the most cases is the fastest, but I also read, that C# can also be used for DirectX programming. How much is the speed difference, or are there other advantages or disadvantages for C# / C++?
0

Share this post


Link to post
Share on other sites
Most of my DirectX learning involved converting DX Samples -> C# and with the exception of startups being slightly slower in C# (although compile times make up for that) I never noticed any performance issues. Plus it was so easy to understand DirectX with less code and no COM crap

Even with terrible programming ;) I have had constant frame rates and nice performance. I had this C++ vs C# issue several months ago, not because of performance but because of almost every tutorial, guide, book was in C++, I suppose thats the downside of doing things in C#, they can all be converted but sometimes you get frustrated with translating;

You dont have to stick with just one language either, you are free to make use of both, personally I say use C# until you know 100% that you need C++ take advantage of both languages but only when you need to, chances are you wont ever need to use C++

I have recently become very fond of using C++ and C# together, it feels so taboo ;) Anyway whatever you are planning on doing will get done very quickly in C# and probably easier to change to careless of what is offered in C++, especially UI related work, which I found to be a pain in DXUT
2

Share this post


Link to post
Share on other sites
If I undestood both post correct, C# is a Little bit slower, but easier to use. I also write C# since 2 years, which was an Advantage of using C#. Are there any Features of DirectX11 unusable with C#? And if there aren't very big differences in the use of DirectX, it should easily be possible to later convert the C# code to C++. Is the wayof execution the same as with normal C# (the code gets compiled to a code, which gets compiled with the JIT during runtime? Also I wanted to know if a type check is made only in the code of C# or also in DirectX, if I use it with C#?
0

Share this post


Link to post
Share on other sites
Microsofts directx wrappers to the .net framework have all been discontinued apart from XNA which uses directx 9 so is a little out dated and won't give you the low level access you want. Slimdx is a 3rd party wrapper and seems to be the way most people go with C#/other .net languages.

C++ is usually compiled straight to native code so doesn't need the .net framework (although there is also a variant of C# for .net). C#'s slowness compared to regular C++ only really comes down to the .net framework, any language using a virtual machine (.net, mono, java etc) is always going to be slower than native code (C, C++).

C# is easier to use than C++. Through slimdx you get the full feature set of dx9, dx10 and dx11, through microsofts outdated wrappers you get full access to dx9 only and through XNA you don't tend to get much access to directx itself but it does use dx9 under the hood.

Slimdx class names etc I believe are slightly different than native C++ directx but conversion of code over to C++ should be possible. Chances are you won't have performance issues on C# anyway, at least not until you start hitting AAA graphics and physics etc that aren't normally possible for a single developer
1

Share this post


Link to post
Share on other sites
Heh... Back when I started learning DX, I was programming in Visual Basic.
Use whatever you're comfortable with, especially if you are just learning and creating smaller scale graphical applications.
Whether you are using one language or the other, the Direct3d pipeline is the same.

For bigger scale project, I would recommend C++. If you are using C# for a large project and have done everything you could to get proper performance in vain, then porting a whole application to a more performant language will suck major balls. Edited by french_hustler
2

Share this post


Link to post
Share on other sites
Now my last two questions. Are there any resources/tutorials that are written in C# (only for the start, a simple example would be enough)? And, theoretically, if I writte the graphic component in C#, should it be possible to write the rest in C++, or am I wrong at this point (I mean that the parts, which consume more CPU power get written in C++, the rest in C#?
0

Share this post


Link to post
Share on other sites
Its possible to link unmanaged DLL's into .net applications, not necessarily an easy process (these basically include C++ class libraries etc) and accessing them is usually done through a .net class laid over the top of the unmanaged code, this is often referred to as a wrapper. Slimdx for example, you make a call to slimdx and then slimdx goes off and makes the calls into the directx library. A simple function like print4squares() will be able to be called with just that one line in a C++ application. If the function is written in C# then it can be called from a .net application with 1 line aswell. But calling it in an unmanaged DLL from .net it might require 5 or 6 lines of code before you get to being able to type the line you need hence why wrappers exist, with the wrapper you only have to type the one line of code again and it deals with conversion for you. Wrappers are still alot faster than straight porting a library to C# though. For example MOgre and Axiom are both versions of Ogre3d for .net. However MOgre is a wrapper around the original C++ library and Axiom is Ogre3d ported straight over to full C# code. With the same demo sample in MOgre I get 2 fps lower than the reference Ogre3d implementation (with a framerate in the multiple hundreds this is hardly significant) but on Axiom I can only achieve around half the original Ogre3d frame rate.

For 1 game I think just going with a single language may be much simpler. C# is still pretty fast and most of the time graphics will be through a wrapper and hardware accelerated. Axiom is probably one of the only non wrapped graphics libraries out there for .net. Physics will depend on what route you go down, rolling your own or using an existing library. Once again alot (but not all) physics libraries for .net are wrappers for existing C++ libraries but unlike graphics probably won't be hardware accelerated (unless you are using PhysX for which there is a .net wrapper for and also happen to have an NVidia graphics card, Bullet also has hardware acceleration as a user option but this is on a recent version that doesn't have a .net wrapper yet). A beginners indie game will be fine in C# coded properly. If you think you can cope with C++ though then by all means go for it. Just to show what .net can do (specifically XNA, not known which language, I assume C#): [media]http://www.youtube.com/watch?feature=fvwp&v=OiGADgezjC8&NR=1[/media]
this is of course just rendering, no physics (I think, the water has waves in it but whether theres any actual physics calculation or its just a pre coded effect I have no idea) or AI going on but damn its pretty. Edited by 6677
1

Share this post


Link to post
Share on other sites
If the other components expose a COM interface you can just add a reference and use the interface directly. Releasing is a bit fiddly but not much, otherwise it's quite straightforward (I've done evil things such as Lotus Notes (spit) interop before, so I can be fairly certain this works!) If you don't want that you could otherwise just write them as standard DLLs and use dllimport. See [url="http://msdn.microsoft.com/en-us/library/aa288468%28v=vs.71%29.aspx"]http://msdn.microsof...8(v=vs.71).aspx[/url] for some more info. Edited by mhagain
1

Share this post


Link to post
Share on other sites
[quote name='147' timestamp='1343749900' post='4964897']
If I undestood both post correct, C# is a Little bit slower, but easier to use. I also write C# since 2 years, which was an Advantage of using C#. Are there any Features of DirectX11 unusable with C#?
[/quote]

So far from what I have seen SlimDX / SharpDX have all the features of DX11, I really doubt they would have things missing, last I read SharpDX was missing a few classes from DX9 but that was about it.
1

Share this post


Link to post
Share on other sites
If you are interested in c++ vs c# question this article may help:

[url="http://www.codeproject.com/Articles/212856/Head-to-head-benchmark-Csharp-vs-NET"]http://www.codeproje...k-Csharp-vs-NET[/url]

It clearly shows that c++ is faster in the most of cases. Despite this I have chosen C#, because it's easier to code and it contain logical name for classes, functions and methods(no acronyms, I hate them in both openGL and directX api). You also doesn't have to worry about memory management. I also find it easier to debug because exceptions clearly states what I did wrong.

You should pick language that you are more familiard with and you sould also think if it will be suitable for your project. If you want to create simple indie game, c# all the way. If you want to create game that will compete with modern games, c++ will be better for this scenario [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Tasaq
0

Share this post


Link to post
Share on other sites
[quote name='JWalsh' timestamp='1343834686' post='4965222']
If you pay special attention to the actual code being used, you'll see that he's intentionally using the slowest parts of C#, vs. the fastest parts of C++, [...]He's also not doing any dynamic memory allocation as part of his tests, which happens to be the part where C# shines.
[/quote]
This might be a little off-topic but could you provide me with some materials on this (not necessary tutorials, maybe articles or apis with faster implementation), I would be very grateful :D
Personaly, I think C# is very underrated language.
[quote name='JWalsh' timestamp='1343834686' post='4965222']
even writing his own HashTable class when the C++ STL version is too slow for him.
[/quote]
True, it also "made my eyes bleed" :)
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1343835570' post='4965226']
C++ is very fast when used by a computer-science expert, who's aware of pointer-aliasing, cache-line-aliasing, pre-caching, data layout trade-offs, balancing algorithmic complexity with hardware realities, etc...

When used by a beginner, C++ is not only slow, but also very dangerous -- with programs seeming to work properly, but actually leaking resources and corrupting their own memory, causing bugs that a beginner has no chance of finding.

C# is much friendlier to beginners, and it's "[i]performance penalties[/i]" aren't really that bad when you're not capable of writing expertly performant C++ code anyway.


Your talent as a computer scientist has a [i]much[/i] bigger impact on performance than whether you're using native [i]vs[/i] JIT/managed binaries.

Also, N.B. the tools that C++ gives you to generate blindingly fast code also do exist in modern revisions of C# ([i]e.g. fixed memory, explicit data layouts, raw pointers, unsafe native code[/i]), it's just that they're generally not used by default because they lead to the same issues that make C++ a dangerous language.
[/quote]

Kind off topic..But this interest me a bit..
When you say beginner, looks like you talking about a beginner programmer, but to me, and correct me if Im wrong, you can master C#/java/whatever, but the only way to became a "no beginner" in C++, is programming in C++... do you agree with this sentence?

I mean, c# and java will teach you OOP much faster than C++ in my opinion, but the only way to learn the stuff that makes C++ powerfull(the ones you mention as being computer-science expert skills), is coding on C++.. Since other languages abstract out all of that stuff..

When I started programming in C# in the beginning of this year I realized how ridiculous hard C++ is, ive been programming only in C++ since I started to learn programming, the difference in productivity is scary. Edited by Icebone1000
0

Share this post


Link to post
Share on other sites
[quote name='Icebone1000' timestamp='1343915857' post='4965522']When you say beginner, looks like you talking about a beginner programmer, but to me, and correct me if Im wrong, you can master C#/java/whatever, but the only way to became a "no beginner" in C++, is programming in C++... do you agree with this sentence?
I mean, c# and java will teach you OOP much faster than C++ in my opinion, but the only way to learn the stuff that makes C++ powerfull(the ones you mention as being computer-science expert skills), is coding on C++.. Since other languages abstract out all of that stuff..[/quote]As I mentioned above, C# has actually added lots of the 'dangerous' C++ features, like raw pointers, and low-level performance tuning features, like explicit data layouts. So if you "fully master" every possibly usage of C#, then those skills will all transfer over to C++.
However, yes, C++ has lots of quirks of it's own that you still have to learn, like the [url="http://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)"]rule of three[/url], and it has it's own idioms such as [url="http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization"]RAII[/url], which doesn't appear in many other languages.
So if you're comfortable with your computer-science and computer-architecture knowledge ([i]which is theory that doesn't depend on any language[/i]) and you've mastered some other languages, you will find C++ much easier to learn than a complete beginner, but nonetheless you will still have plenty of new material to learn.[quote]When I started programming in C# in the beginning of this year I realized how ridiculous hard C++ is, ive been programming only in C++ since I started to learn programming, the difference in productivity is scary.[/quote]Indeed, they don't call it a "productivity language" for nothing.
So, if you're a beginner programmer, it would be wise to start with a language that lets you focus on programming, rather than also having to focus on language-specific quirks and difficulties (which C++ has plenty of). Edited by Hodgman
2

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1343916648' post='4965525']
As I mentioned above, C# has actually added lots of the 'dangerous' C++ features, like raw pointers, and low-level performance tuning features, like explicit data layouts. So if you "fully master" every possibly usage of C#, then those skills will all transfer over to C++.
[/quote]

And C++ has added a lot of RAII features like smart pointers being part of the stl library.
I think that the language is moving in a direction that makes it really easy for beginners who have low knowledge of things like memory management to come in and write proper applications. Though you still have to learn the proper usage of such features since it isn't handled under the hood, it seems that both languages are advancing towards a common middle ground. But I'm just playing devil's advocate.

In the end, a programming language is just a tool. Like a sword-master, it takes a lot of practice to be proficient with your tool. I still say, stick with what you're comfortable with.

I do have a question though. Why is C# a "productivity language"? I've searched a bit and read couple threads on stack overflow but haven't found huge advantages in using C# over let's say C++ & QT. I've been programming with C++ for a loooong time now. Why should I pick up C# to further my productivity? Edited by french_hustler
0

Share this post


Link to post
Share on other sites
[quote name='french_hustler' timestamp='1343929508' post='4965603']
I do have a question though. Why is C# a "productivity language"? I've searched a bit and read couple threads on stack overflow but haven't found huge advantages in using C# over let's say C++ & QT. I've been programming with C++ for a loooong time now. Why should I pick up C# to further my productivity?
[/quote]

Two reasons:

1. The language itself has many features that makes it easier to be productive. You can do more with less lines of code, and the code that you do have to write tends to be less repetitive and more direct. Simplicity and elegance have been major design goals throughout the lifetime of the language. As a result, it's just easier and more enjoyable to use C# than C++. I always find it a little tedious having to go back to C++.

2. The ability to access the .NET Framework Library and all of the related frameworks means a whole lot of code is written for you when using C#. If you just look at some of the namespaces of the .NET Framework Library there is MS Build integration, all the container classes, language generation, SQL Server bindings, OO wrappers around Win32 API Library Functions, CodeDOM, Diagnostics, Drawing, Enterprise Services, IO, Isolated Storage, Ports, Media, Messaging, Network programming, Reflection, RPC, Security, Authentication, Cryptography, Threading, Transactions, XML parsers & Serializers, XPath queries, and tons of Web stuff: Complete HTTP engines, Email classes, various protocols, etc...

In addition to all the basic classes in the .NET Framework Library you also have WinForms for creating GUI Windows applications, WPF, WF, WCF, and ASP.NET.

So I guess the better question is, when you want to write a complex Windows Application with multiple windows, tab controls, tree controls, animations, etc... How do you do it in C++? Likewise, if I asked you to create a database application that made connections to multiple databases, performed transacted queries against the databases and displayed results in a GUI application, how would you go about doing it? How about, write a GUI application that lets you enter in the email address of multiple people, subject, and a message body and then send the message out to all the people in the email list in formatted HTML over TLS secured SMTP?

Most of these things would make the average C++ programmer shiver. At the very least they'd be searching the interwebs for available libraries, and at worst they'd be looking for RFCs on protocols to begin implementing them themselves. In C#, the above programs range from a couple dozen lines of code to a couple hundred (maybe some in the low thousands), because most of the boilerplate stuff is done for you. It's literally half a dozen lines of code or less to open a database connection to SQL database and make a query. The support provided to programmers to develop "every-day" applications is just amazing to me.
2

Share this post


Link to post
Share on other sites
Basically what JWalsh said; I recently spent 2 months at work writing C# code for a new data build system - I was productive, relaxed and enjoying myself :D

Even the things which would take annoying amounts of C++ code and extra libraries are a breeze in C#; want to load an XML file and then fill a container based on a subset of the data include? Easy! Just load with XDoc and then use LINQ to filter the data and return an anonymous object type with the fields you want in it.

Don't get me wrong; I still enjoy using C++, certainly with the C++11 features but C# is where I'm headed whenever I want tools or to do things quickly.
2

Share this post


Link to post
Share on other sites
Thanks for the insight guys.
I'm very tempted to start messing with C#. It definitely seems like it would be the way to go for creating utility tools that'll generating assets for my engine.
0

Share this post


Link to post
Share on other sites
[quote name='french_hustler' timestamp='1343929508' post='4965603']I do have a question though. Why is C# a "productivity language"? I've searched a bit and read couple threads on stack overflow but haven't found huge advantages in using C# over let's say C++ & QT. I've been programming with C++ for a loooong time now. Why should I pick up C# to further my productivity?[/quote]I'm not saying you should, but it's damn popular, so might be [url="http://www.adrianhofman.com/blog/?p=4"]valuable[/url] to learn. There's plenty of C[font=courier new,courier,monospace][i]x[/i][/font] vs C[font=courier new,courier,monospace][i]y[/i][/font] threads already on the forums. The short and annoying answer is: try it out and see ;-P
N.B. I'm not a C# fanboy; C++ is [b]by far[/b] my favourite language, and I'd recommend every serious programmer learn C++ after learning the basics of programming ([i]I started with BASIC, AppleScript and a simple assembly language to learn the basics[/i]). After using both for a decent period though, it's obvious that C# gives you more tools out of the box (bigger standard library) and it requires far less programmer skill to use correctly.
[quote name='french_hustler' timestamp='1343929508' post='4965603']I think that the language is moving in a direction that makes it really easy for beginners who have low knowledge of things like memory management to come in and write proper applications. Though you still have to learn the proper usage of such features since it isn't handled under the hood, it seems that both languages are advancing towards a common middle ground. But I'm just playing devil's advocate.[/quote]The difference is their starting points -- I'd liken it to comparing the [url="http://www.theatlantic.com/international/archive/2012/07/a-land-without-guns-how-japan-has-virtually-eliminated-shooting-deaths/260189/"]US constitution to the Japanese constitution[/url]. One starts off dangerous and adds features to make it safer, the other starts off safe and adds features to make it dangerous.
With C++, you're also following the "pay for what you use" concept at all times, which relies on the fact that you explicitly know what every line of code really means. For example, if you pass a smart-pointer by value (instead of by const-reference), then you're explicitly asking for the reference counter to be incremented and decremented at the start/end of your function call ([i]which may or may not be what you want[/i]). Also, smart-pointers don't at all fit into the same category of C#'s references -- e.g. smart-pointers require the explicit choice between strong and weak links in order to avoid circular references, whereas C#'s GC are built assuming that that you'll create any kind of graph with them. Also, despite all of the nice library additions to C++, you're still relying on these libraries to have debug code to detect invalid usage (e.g. out of bounds accesses), and no library can detect invalid language usage (e.g. writing to a bad pointer). Conversely, C# can detect these abuses at the language level (in debug or optimised builds) and prevent you from corrupting your memory.
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0