Getting started with C++

Started by
16 comments, last by hawksprite 11 years, 9 months ago
I've done a lot of programming in C# with XNA in both 2D and 3D environments. But due to its performance issues I've recently begun looking into moving into the world of C++ with Direct X.

What's the best way to get started with game development in C++? Should I use a wrapper/graphic engine or just let it all hit the fan and try using the Direct X SDK straight up.

Thanks.
Advertisement
c++ is not something you move to and gain 9001x performance.

badly written c++ code runs worse than c#
if xna wasnt enough you did it wrong.

in reality gpu is almost always the bottleneck.
Not specifically to do with Direct X, though it does cover it for 2d, but you could checkout this.

http://msdn.microsoft.com/en-us/library/ff381399%28VS.85%29.aspx
Understandable, but even if it's a small increase I'd rather learn the superior platform to develop games on.

c++ is not something you move to and gain 9001x performance.

badly written c++ code runs worse than c#
if xna wasnt enough you did it wrong.

in reality gpu is almost always the bottleneck.
Thanks for the tutorial, i'll look into as soon as I can.


Not specifically to do with Direct X, though it does cover it for 2d, but you could checkout this.

http://msdn.microsof...399(VS.85).aspx
If you only had C# experience and no C++ experience, I suggest you learn the things which are in C++ and not in C#.
Such like memory management (RAII, etc), C++ idioms (Google it). Wrongly understanding them may lead you crazy. :-)

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.

good luck with your adventure then :)

tips:
- Every new call should have a delete counterpart.
- pass parameters by reference when they are larger than 4bytes.
- stack memory is almost always faster than heap, but less flexible.

c++ is not something you move to and gain 9001x performance.

badly written c++ code runs worse than c#
if xna wasnt enough you did it wrong.

in reality gpu is almost always the bottleneck.


This,

It is highly unlikely that you've hit a performance wall with C# as properly written C# code running on Microsoft .Net has pretty much the same performance as standard C++ code compiled with Microsofts C++ compiler. The advantages you get with C++ lies primarily with memory management (you can get better cache utilization if you know what you're doing (or far, far, far worse if you don't) and the ability to use non standard extensions for things like SSE.

For C# i'd recommend taking a look at Mono.SIMD if you need a performance boost and try to think about how you allocate memory (you actually have quite a bit of control over this, avoid excessive creation of temporary objects as it tends to both give the garbage collector a hard time and fragment your heap(which greatly reduces cache performance)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

tips:
- Every new call should have a delete counterpart.
- pass parameters by reference when they are larger than 4bytes.
- stack memory is almost always faster than heap, but less flexible.


True, although if you use exceptions in your software, then you really shouldn't ever be calling delete. You need to be using a smart pointer container such as std::auto_ptr, std::tr1::shared_ptr.

What is quite cool about the newer smart pointers is you can pass a deleter function to it for memory that needs to be freed differently (such as C libraries or abstracting wierd memory systems like in Irrlicht). For example you can pass fclose to a smart pointer containing a file descriptor created by fopen (i.e during it's construction.). This is perfect for opengl stuff such as glFreeTextures or glFreeBuffers

Although in C# (or java) you should really be doing something similar using either Close or Dispose with certain IDisposable derived classes. So frankly I don't see any reall added difficulty here. If anything the smart pointers look a lot neater than loads of try, catch, finallys around the place. Or even using which only works in single functions anyway.
http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.
Read these articles/guides, should be good for starters:
http://geekswithblog...hort-guide.aspx // general intro, "C# to C++ – A Somewhat Short Guide", incl. some C++11 features
http://www.hackcraft.net/raii/ // RAII intro
http://visualstudiom...et-smart.aspx// smart-pointers intro
http://akrzemi1.word...alue-semantics/ // value-semantics intro

If you need a more general reference, this one is pretty good (also includes C++11 additions):
http://cppannotations.sourceforge.net/cppannotations/html/

This topic is closed to new replies.

Advertisement