Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Switching from XNA to DirectX9 for 2D platformer

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Vendetta8247   Members   


Posted 16 August 2014 - 09:45 PM

Hello, I've joined the community today and I'm really interested in making games. This topic is not just a topic by newbie that asks for all the links and because he is too lazy to find 'em by himself. I've already started developing my game using xna. I've succeeded in the game physics, collision, drawing, shooting and made it pretty fast. But it seems to me that xna is working much slower than directx. That is why I've decided to switch. So my first question is: was it a smart decision to start studying directx? I want to know how it works on a lower level than xna. And so comes my second question. What do I need to know about directs and developing in 2D before I start? I know that the main focus of directx is 3d. So I understand that I don't need to know everything. My third question is: what exactly should I focus on in learning directx? And the last thing I would like to ask is if there are any good articles for my needs. I need to know the basics of the platform and its 2d divisions more specifically. Thank you for reading all this.

#2 Sparkon   Members   


Posted 17 August 2014 - 03:19 AM


I'll just point out few things :

- XNA bottleneck : As long as the game runs fine (60+ fps ) using XNA i don't see the need to switch to D3D for performance reasons. If you have a real bottleneck is probably somewhere else or you draw something like tens of thousands of particles in an inefficient way. The statement [ xna is working much slower than directx ] well.. it's too wide, it is true for obvious reasons, but at the same time, this performance difference should be negligible for the most part.  


- XNA / C# D3D / C++ : by switching to D3D9 i guess you were considering moving to C++ ( but you might be talking about Managed DX ). Learning D3D will be fulfilling in many ways, but not a wise choice if your purpose is to complete the game as soon as possible. C++ is a whole another language and will massively ( usually, don't take my word for wisdom ) increase your development time. 


- D3D9 : there is a new, much better ( depends ? ) version called D3D11 that provides backward compatibility with D3D9 hardware http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876(v=vs.85).aspx


- 2D with D3D : after you've properly chosen to use D3D11 and start looking for 2D help people will tell you : 2D is nothing else than rendering textured quads, well that's it really. There are many techniques that you can use ( naming Geometry Shaders, Instancing, Batching ) but it all revolves around 2 triangles being textured. If you come from XNA i'd really tell you to check out DirectXTK ( https://directxtk.codeplex.com/ ). It provides some XNA-like modules for D3D11. If you still don't want to use it, just dig in the source code to learn more.


- Platform games : same concepts apply to D3D


Have fun & happy coding : )

Edited by Sparkon, 17 August 2014 - 03:21 AM.

#3 Vendetta8247   Members   


Posted 17 August 2014 - 03:50 AM

Sparkon, thank you very much for a detailed answer. The main purpose of switching to DirectX was getting more familliar with the lower-lever programming. The reason why I've chosen the 9th version is that it is supported by the WinXP and D3D11 is not (or am I wrong?). So the problem is not the hardware compatibility but software. So now I have only one question left. Are there any accessible articles about the pure D3D for the 2D purposes or is it a type of knowledge that can wait?


And, by the way, I forgot to mention that in future I'm going to port my game to other devices and if I'm right I will need to use OpenGL (MonoGame is rumoured to be full of bugs). What about openGL? Are DirectX or XNA better than OpenGL for Windows? How easy will it be to go to other platforms?

Edited by Vendetta8247, 17 August 2014 - 04:09 AM.

#4 Sparkon   Members   


Posted 17 August 2014 - 04:47 AM

I'll try to address your question the best way i can ( i'm not the most experienced around here) ^^ :
- Direct3D11 should be available from Vista SP2+ if i'm not wrong. Choosing whether to support Windows XP or not is totally your choice, i would probably read some hardware surveys ( http://store.steampowered.com/hwsurvey | http://stats.unity3d.com/pc/index.html ). Yes, there are still many peoples running Windows XP ( unfortunately ) biggrin.png

- I'm sorry i'm not aware of any reference article that covers 'doing 2D with D3D', still, as i wrote the previous post and if you start googling around, most of the answers will reference :
- Textured quads
- GS
- Batching
and this is exactly how XNA would do it ( not GS tho ) [ https://directxtk.codeplex.com/SourceControl/latest#Src/SpriteBatch.cpp ]

- Direct3D vs OpenGL on Windows, argh this question ^^ Don't like this terrain... I cautiously tell you that D3D 'should' 'is supposed' 'might' be better than OGL on Windows platform mostly due to hardware support, but Valve wouldn't agree with me ( http://blogs.valvesoftware.com/linux/faster-zombies/ ) [ I took 'better' for 'faster' ]. I personally prefer D3D API to the OGL's one, but that's a matter of taste.

- I'm just going to mention this library, i don't think it really fits your purpose and i hate its API, but you've probably heard of it and you will : Direct2D. Developing games / wrapping it up is quite painful for the way it is structured, but undoubtedly has a crazy amount of features.

If you code your entire game with no wrapping, porting it to OpenGL is probably a hassle, if you start wrapping D3D calls / resources it will not be that hard to port it to OGL, not saying it is easy tho.

Another road you might take if you are going to port the game later is just dive into OGL and leave D3D aside for the moment.

Hope i was helpful, and you if need anything else, don't hesitate to PM me.

Happy coding smile.png

Edited by Sparkon, 18 August 2014 - 03:46 AM.

#5 Starnick   Members   


Posted 18 August 2014 - 09:22 AM

How exactly are you quantifying “XNA seems to be running slower than DirectX”? What are you comparing your game to? Whatever the case is, it’s not that useful in my opinion. Generally you’re going to be using C++ with the DirectX API, and C# with the XNA (which is just a wrapper around Direct3D 9). You’re really comparing unmanaged and managed applications, and there will always be some level of overhead with a managed application.


Don’t get caught in the trap of “Im not doing it like the makers of Crysis, therefore what I’m learning is useless”. You’re a beginner and a one man team; any experience you gain, any tools and languages you learn is an asset for the future, especially if you’re making software development as a career. And even with the expected overhead of a managed application, C# is good enough for professional quality real time 3D graphics applications (games and anything else). And that is certainly true for simpler 2D games. Go on steam, there are quite a few good games (largely indie) that stick with C# and XNA (or one of the wrappers for Direct3D out there).


Learning Direct3D9 would be a step back by the way, it’s an old API at this point. Most of the world is moving to or has moved to Direct3D11, which has a cleaner structure to it and is generally more performant due its design (less state switching, immutability, etc). You’re interested in learning low-level stuff and what's being used right now…well that’s it! Learning 9 first will do you a disservice when you try to learn something more modern. And, if you used XNA 4.0, they took some inspiration from Direct3D10 which has a similar organization and layout to the Direct3D11 API.


So my suggestion is stick with C# and learn about SharpDX (www.sharpdx.org), which is a managed wrapper around Direct3D [Avoid "Managed Direct3D" as it's an old and outdated library at this point, XNA replaced it!]. Unlike XNA, SharpDX is more or less a 1-to-1 mapping to the actual API. It’s fast, well maintained, and also has a Toolkit which is similar to that DirectXTK Sparkton linked you to (which means it is XNA-inspired). That sounds like it’s the next step in what you’ve already been doing.


A good and useful book on Direct3D11 is this one: Practical Rendering and Computation with Direct3D11


I can’t tell you much about MonoGame (all software has bugs) but there are some released games for that API. For Windows platforms they do use SharpDX, for other platforms they use OpenGL. It would be useful (if you don’t want to do the Unity route) if you want to deliver your app to other platforms. But it sounds more like you want to learn tech, so don’t over extend yourself. Stick to one path, learn it well, and then tackle the next thing.

#6 Vendetta8247   Members   


Posted 18 August 2014 - 10:33 AM

Starnick, thank you very much for your answer. I made the conclusion that XNA is a slower toolkit because it is something that is built on Direct3D. And C# is considered to be slower. Now I'm a one-man team but some day I hope to join or create a team and that is why making serious stuff is in plans. And if I'm right serious stuff is done on DirectX. The 9th version interested me because of supporting WinXP. And for me it's not important which language to code on. I used to code on Java but then made it to C# with its XNA. So learning a bit of advanced C++ would be nice any way. Thank you very much for the book link, I will take a look on it and will consider your advices.

#7 mhagain   Members   


Posted 18 August 2014 - 12:07 PM

My advice.


Be absolutely certain that Windows XP support is something you really need before making the decision.  Unless you're aiming for a target audience where you know for a fact that Windows XP still dominates, you can very probably afford to just forget about it.


If you do decide to still support XP, you should probably develop on XP, and use a downlevel version of your development tools.  That way you can be more confident that you don't accidentally pull in features or APIs from higher versions of Windows.  XP support is a lot more than just a DirectX version.


Also be certain to test on more recent versions of Windows.  You can ignore Vista; a good general rule is that if it works on Windows 7 it will also work on 8+.  Be certain to test on a machine with UAC enabled (if a game requires me to disable UAC I won't install it; that's a global change to solve a local problem).


Consider using SlimDX or SharpDX so that you can continue developing in C# but make the switch; the reasoning here is that you'll stand a better chance of success if you only have to deal with one new thing at a time.


OpenGL portability is a myth.  The driver situation is a disaster, the tools are nowhere near as good as for D3D or XNA, much documentation, samples or tutorials are horrifyingly outdated, and most mobile devices use OpenGL ES rather than full OpenGL; you can't just take desktop OpenGL code and expect it to work on these.  Despite what you may read elsewhere, OpenGL is not the preferred API on any of the consoles.


Don't forget that portability covers a lot more than just the 3D API used.  You'll also need to port your windowing code, your input code, your networking code, your sound code, etc.  It's not enough (and not true) to just say that using OpenGL makes you portable.


You can develop using D3D on Windows and still be portable.  Just write an OpenGL (or whatever API the target device uses) rendering layer as well.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.