Jump to content

  • Log In with Google      Sign In   
  • Create Account


Getting started with C++


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
17 replies to this topic

#1 hawksprite   Members   -  Reputation: 124

Like
0Likes
Like

Posted 08 July 2012 - 08:35 PM

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.

Sponsor:

#2 saejox   Members   -  Reputation: 714

Like
3Likes
Like

Posted 08 July 2012 - 09:21 PM

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.

Edited by saejox, 08 July 2012 - 09:23 PM.


#3 timnwells   Members   -  Reputation: 101

Like
0Likes
Like

Posted 08 July 2012 - 09:31 PM

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

#4 hawksprite   Members   -  Reputation: 124

Like
0Likes
Like

Posted 08 July 2012 - 09:35 PM

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.



#5 hawksprite   Members   -  Reputation: 124

Like
0Likes
Like

Posted 08 July 2012 - 09:35 PM

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



#6 wqking   Members   -  Reputation: 756

Like
1Likes
Like

Posted 08 July 2012 - 09:49 PM

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. :-)

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.


#7 saejox   Members   -  Reputation: 714

Like
1Likes
Like

Posted 08 July 2012 - 09:49 PM

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.

#8 SimonForsman   Crossbones+   -  Reputation: 5450

Like
1Likes
Like

Posted 08 July 2012 - 10:02 PM

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)
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!

#9 Karsten_   Members   -  Reputation: 1200

Like
0Likes
Like

Posted 09 July 2012 - 03:25 AM

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.

Edited by Karsten_, 09 July 2012 - 03:28 AM.

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.


#10 Matt-D   Crossbones+   -  Reputation: 1403

Like
1Likes
Like

Posted 09 July 2012 - 11:22 AM

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/

Edited by Matt-D, 09 July 2012 - 11:26 AM.


#11 hawksprite   Members   -  Reputation: 124

Like
0Likes
Like

Posted 09 July 2012 - 11:39 AM

Thanks for all the guides and advice.

I'm not reconsidering the switch and wondering if there's a better way to use C# other then XNA.

But at the same time i'm still going to learn C++ as a platform and as I get better at it slowly transition into it.

#12 SimonForsman   Crossbones+   -  Reputation: 5450

Like
0Likes
Like

Posted 09 July 2012 - 01:06 PM

Thanks for all the guides and advice.

I'm not reconsidering the switch and wondering if there's a better way to use C# other then XNA.

But at the same time i'm still going to learn C++ as a platform and as I get better at it slowly transition into it.


Other than XNA you also got OpenTK (crossplatform), SlimDX (DX11 IIRC) and ofcourse Unity.

For C++ there are fewer really good options that are easily accessible, CryEngine 3 however is free for non commercial use and is available at a 20% of revenue royalty rate for indies (So you only have to pay if you make any money, allthough if you succeed it will get very expensive(still cheaper than UDK though)), getting familiar with OpenGL / Direct3D is a good idea aswell, if you plan on writing your own engine (Which really is the only reason one would willingly touch C++ for a game these days) you should take a look at lua, python or angelscript (or something else, there are tons of nice options) to add scripting support (an engine that requires the game to go through a 20 minute recompile each time you adjust the AI or tune your heat seeking missiles will become horribly painful to work with)
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!

#13 WavyVirus   Members   -  Reputation: 735

Like
0Likes
Like

Posted 09 July 2012 - 01:19 PM

Have you profiled your XNA game? Where are the bottlenecks?

If you haven't identified the specific parts which are limiting performance then you're almost certainly not hitting the limits of XNA.

Also, I feel I have to call you out for referring to c++ as 'superior'. It may or may not be the most appropriate choice given a particular set of requirements, but is not superior in general. In many ways, and in many applications, C# is probably the better choice. It's true that somebody who is sufficiently experienced can usually squeeze out an extra bit of performance in C/C++/assembly, but it is becoming increasingly rare that it is worth the considerable extra effort (particularly since more and more work is being offloaded to the GPU these days).

#14 laztrezort   Members   -  Reputation: 950

Like
0Likes
Like

Posted 09 July 2012 - 02:52 PM

I don't think there is anything wrong with exploring C++, especially if you have logged some programming with C# or other languages. If nothing else, it will reveal a newfound respect and love for reflection, a sane build model, sane debugging system, fleshed-out standard library, and memory management Posted Image

I also agree with those that have questioned hitting a performance bottleneck in XNA. From what I hear there are a few gotcha's when targetting XBOX (and other limited platforms), but I can't imagine where a PC would have trouble CPU side that would magically be solved by just switching to C++.

#15 hawksprite   Members   -  Reputation: 124

Like
0Likes
Like

Posted 09 July 2012 - 08:14 PM

I've decided to go with SlimDX for my next project. Thanks to all who gave me advice, i actually found a handful of engines and platforms I never knew existed.

To clear up the rest of the questions most of the bottleknecking in XNA was my own poor code just little bits in A* alogrithims that were dropping the FPS by like 10 and so on so forth. I understand that C++ wouldn't fix this but I simply wanted to start my next project on a better platform. I didn't quite write my original post all to amazingly.

To WavyVirus I agree and probably shouldn't have jumped to saying C++ was better, I simply meant for game programming. When it comes to desktop application programming or basically any other situation i'd never consider using C++ over C# or something like ruby.

While I still want to learn C++ and memory management aspects, etc. I'm going to stick with C# for now but use SlimDX so I have a little more availability instead of being limited to just DX9.

Finally; i've ran into a bit of an issue with SlimDX but I made a second post for that here.

#16 WavyVirus   Members   -  Reputation: 735

Like
0Likes
Like

Posted 10 July 2012 - 04:57 PM

To WavyVirus I agree and probably shouldn't have jumped to saying C++ was better, I simply meant for game programming. When it comes to desktop application programming or basically any other situation i'd never consider using C++ over C# or something like ruby.


Still, I think that saying that C++ is better for game programming is a very bold claim. There are some situations (e.g. developing the latest and greatest big-budget title, with cutting edge graphics being a selling point) where it is still necessary to use C/C++ for performance reasons. Also, sometimes the platform you are developing for (console/mobile etc) restricts your options. But for many of the games that an indie or hobbyist developer is likely to have the resources or desire to create, C++ is not the optimal choice as the same result can be achieved more quickly and easily by other means. Often the lack of a team of artists means that a small developer will naturally gravitate away from game ideas which depend on super-detailed graphical content, and instead focus on areas where they can be more competitive like original gameplay, story, stylised art etc.

A not-so-terrible analogy would be cars. Is a Formula One car the best for driving? Really this depends on the situation (what sort of track surface? lots of corners or long straights? Are you driving around town? A rally car, Mini or drag racer might be superior in some situations) and also on the driver (what are they familiar with? I could probably drive my own little car around a track faster than an F1 car as I would spend most of the time either stalling or killing myself in the more powerful and complex machine).

Having said that, I don't want to discourage you from learning C++ and getting deeper into things like memory management - it can be a lot of fun, is still the appropriate choice in some situations, and will improve the code you produce in other languages. Just reminding you that these things aren't black and white - c++ is just another tool in your toolbox to pull out when you recognise that it the right one for the job.

#17 BinaryPhysics   Members   -  Reputation: 294

Like
-1Likes
Like

Posted 10 July 2012 - 05:30 PM

I'd actually recommend looking at ANSI C first. There's a lot of subtle stuff that C++ carries over from C (not surprisingly). That said I wouldn't treat C++ as an extension of C so that isn't really a necessity.

Also, I'd definitely look at COM before you look at DirectX. The book Inside COM is great (old though).

Edited by BinaryPhysics, 11 July 2012 - 09:15 AM.


#18 hawksprite   Members   -  Reputation: 124

Like
0Likes
Like

Posted 11 July 2012 - 09:44 AM

True true, thats mostly while I decided to go with SlimDX for now but still plan on learning C++ in the future. Thanks for the analogy BTW, clears it up pretty well.


To WavyVirus I agree and probably shouldn't have jumped to saying C++ was better, I simply meant for game programming. When it comes to desktop application programming or basically any other situation i'd never consider using C++ over C# or something like ruby.


Still, I think that saying that C++ is better for game programming is a very bold claim. There are some situations (e.g. developing the latest and greatest big-budget title, with cutting edge graphics being a selling point) where it is still necessary to use C/C++ for performance reasons. Also, sometimes the platform you are developing for (console/mobile etc) restricts your options. But for many of the games that an indie or hobbyist developer is likely to have the resources or desire to create, C++ is not the optimal choice as the same result can be achieved more quickly and easily by other means. Often the lack of a team of artists means that a small developer will naturally gravitate away from game ideas which depend on super-detailed graphical content, and instead focus on areas where they can be more competitive like original gameplay, story, stylised art etc.

A not-so-terrible analogy would be cars. Is a Formula One car the best for driving? Really this depends on the situation (what sort of track surface? lots of corners or long straights? Are you driving around town? A rally car, Mini or drag racer might be superior in some situations) and also on the driver (what are they familiar with? I could probably drive my own little car around a track faster than an F1 car as I would spend most of the time either stalling or killing myself in the more powerful and complex machine).

Having said that, I don't want to discourage you from learning C++ and getting deeper into things like memory management - it can be a lot of fun, is still the appropriate choice in some situations, and will improve the code you produce in other languages. Just reminding you that these things aren't black and white - c++ is just another tool in your toolbox to pull out when you recognise that it the right one for the job.






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.



PARTNERS