I'm currently in the planning stage for my next game, and since I've been away from C++ for a while I have some questions about helpful libraries. I plan on making a 2D game with SDL, constructing my own simple 2D engine. I plan on making this game for the PC.

What libraries would you recommend to make this process easier?

What about unittests?

What about an enforce operator to throw exceptions?

int a = 1;
enforce(a == 2); //Throws an exception, 

Specifically, i'm looking for general purpose libraries, that implement that make my life easier (like boost). Also, a helpful library for physics/collision, AI, XML file parsing (specifically working with the Tiled map editor), and any others that you guys have used that are useful in a 2D game.

  • \$\begingroup\$ I thought that C ++ 11 had for each... \$\endgroup\$ – jcora Mar 24 '12 at 18:49
  • 1
    \$\begingroup\$ You're right, my fault, it added the "range based for" that iterates over all elements in the list \$\endgroup\$ – RedShft Mar 24 '12 at 18:52
  • 1
    \$\begingroup\$ A terrible language feature, IMO. \$\endgroup\$ – DeadMG Mar 24 '12 at 19:37
  • \$\begingroup\$ Why would you say that? \$\endgroup\$ – RedShft Mar 24 '12 at 19:40
  • \$\begingroup\$ nevermind, 13 chars \$\endgroup\$ – dreta Mar 24 '12 at 20:41

Come up with a game first, see what you want and need. When you have specific problems, you can use google to solve most of them, for the remaining few there's gamedev.stackexchange.

I can suggest Box2D, because it's a great physics library, but what's that doing for you, you'll go "there's a 2D physics library, maybe i'll make a 2D game with physics in it"? That's the absolute wrong way of going about designing games.

I can suggest SFML for 2D graphics, but that's not right aswell. What if you want a game with complex visual effects or you want the ability to texture random polygons, you can't do that with SFML.

Pick your tools for the job, not the other way around.


boost::foreach works pretty much the way you want :)

Wikipedia has a nice list of C++ unit testing frameworks.

You could make your own enforce function pretty easily, something like this I suppose:

void enforce (bool expression)
    if (!expression) throw Exception(5);

where Exception would be a class defined by you. How you go from this to an enforce function that tells you more about what went wrong though, I'm not sure.


AI will be game specific. There are not a lot of general AI libraries, and even fewer designed for 2D problems.

Regarding other libraries, since you mentioned Boost, just use that.

For your "enforce" function, you need only a simple assert system. It takes only a few minutes to build your own. I would recommend against having it throw exceptions. Exceptions have a lot of problems, I'm fairly certain you're not at the level of writing exception safe code, and when it comes to debugging the exception model loses a lot of useful information. I have my assert macros log the failed test, the file/line/function, call __debugbreak(), and then abort. Much better for debugging than an exception ever will be. Of course only intended for programming errors and not errors of invalid user input, but the latter if better dealt with in other ways anyway.

Box2D is the popular choice for physics in 2D games.

Finally, for unit tests, you might check out Googles test library. Though again, writing your own simple version of that takes a matter of minutes if you have a decent proficiency in C++.


Simple OpenGL Image Library, devIL, and AssImp are some fairly nice content importers.

Configurable Math Library is a fairly nice linear algebra library, and I believe boost has one as well.

And finally, FreeType-GL is a text-drawing library that I haven't used, but should work fairly well


I have to second what @dreta said about coming up with the game first, and figuring out what you may need... That being said, since you're using SDL for 2D, obviously SDL has lots of libs that were made just for it to help you out. SDL_mixer, SDL_ttf, SDL_image are all obvious choices for basic tasks. Box2D, Torque 2D, ODE are all great choices for physics, ODE though it's recommended to be outdated and is technically no longer under construction officially, was used by the game World Of Goo. Which has incredible physics and I've not seen a single physics glitch in the three times I've beaten it (personally).

Regardless of whether your game is 2D/3D whatever, I've always been a sucker for a useful script engine. So Lua and Python would be my first choices any day. People say that Python is not good for an embedded or extension script engine for games, but I've used it personally and it's equivalent Lua codes worked actually slower than the Python. I've heard of people using JavaScript in games also, a big one to note is Wolfire's Overgrowth which uses JavaScript for interaction with the other world stuff.

As far as graphics go, it's well known, easy to set up, and perfectly acceptable to use OpenGL built into your SDL games, even for 2D graphics. One game to name that isn't released yet that we're expecting new videos on soon is the http://elysianshadows.com/ project which uses OpenGL accelerated SDL, for 2D.

For XML I stick with tinyXML almost all of the time, it's a great library and it works extremely fast with relatively minimal overhead. To me it just feels cleaner than other XML libraries.

PS: I didn't really get into the other stuff you mentioned, because it looks like everyone else provided great answers for those.


Not the answer you're looking for? Browse other questions tagged or ask your own question.