If you haven’t gone through Setting everything up – Part 1, do that now (I’ll wait) so that everything here will make sense.
Step 4 – Installing Box2D: In order to get Box2D to play well with Visual Studio, you need to go through a few steps, which are relatively painless. In order to get it working, I originally followed the steps presented by aneelkkhatri, here. However, there are a few modifications that need to be done. So, for the sake of completeness, I’m going to go over it all:
- The latest release at the time of this writing for Box2D is 2.2.1, and it comes with a premade Visual Studio 2010 solution, so there is no need to download cmake. Instead, just open Visual Studio and navigate to the Box2D directory and go into the Build\vs2010\ directory and open the Box2D.sln solution file. Note for VS2012 users: You may get prompted saying that this solution was made with an old version of VS and ask if you want to update, I would suggest clicking Don’t Update.
- Once you have the solution loaded, you will see there are five projects: Box2D, FreeGLUT, GLUI, HelloWorld, and Testbed. We only need to concern ourselves with the Box2D project, so go ahead and right-click on that and choose “Build.” (This ends the ‘one-time-only’ portion of the setup, and from this point on, you will need to do the remaining steps every time you start a new project.)
- Once that is built you can close down this solution and we are now going to start our first demo. Don’t Panic! This will be pretty simple, just so that we can ensure everything is installed correctly and working J So, let’s go to File>New Project. Choose Visual C++ and select Empty Project. Now just give it a name, I’m going to call mine Box2D_SFML_Test.
- Once our solution is created, right click on the Box2D_SFML_Test project and choose “Open folder in File Explorer” Now we are going to create a folder named ‘lib’
- Once that is created, we’re going to copy the Box2D.lib and box2d.pdb files that we just built from the included solution into our new lib folder (They should be in [Box2D]\Build\vs2010\bin\Debug)
- Now, from our Box2D extract directory (the same directory as \Build\), we’re going to copy Box2D into our new project’s folder: We do this because there are some additional header files within this Box2D folder that we will need later on.
- Now, we need to go into our project’s Properties and do some configuration. So right-click on the project Box2D_SFML_Test>Properties. Under Configuration Properties>C/C++>General, we’re going to set Additional Include Directories to “./”
- Then under Configuration Properties>Linker>General, change Additional Library Directories to “./lib” Still under Linker, but this time Linker>Input, click the values for Additional Dependencies, and click the drop-down arrow and choose “edit…” Now enter “Box2D.lib” and hit OK. And then Apply to the Properties window. That will end setting up Box2D, next time we’ll look at how to install SFML