If you have not yet gone over Setting everything up – Part 1 and Setting everything up – Part 2, I highly recommend you do so, otherwise you may be as lost as Marty McFly was in 1955, and I don’t even have a DeLorean, so you would be really screwed…
Step 5 – Install SFML: A lot of this is going to look familiar, as we do the set up with SFML almost identically to Box2D. This comes primarily from the SFML website under tutorials (found here), but again, for completeness I will place my steps below. For the following steps, we will be using the directory that we extracted SFML to up in Step 3, at the time of this writing, the current version is 1.6.
- Go into our project’s Properties window as we did above, and go to Configuration Properties>VC++ Directories and click on Include Directories and as we did before, choose “Edit..” and then click the “New Line” button and on the new line, click the “…” button
- Now go into the directory you extracted SFML to and we’re going to select the “include” directory and then click Select Folder and then click OK
- Next, we’re going to do the exact same thing but for the Library Directories and this time we’re goig to choose, you guessed it, SFML’s lib folder
- After that, we’re going to go to Linker>Input, and under Additional Dependencies (this should seem familiar), we’re going to add “sfml-system.lib” to our list and then press OK
- The last thing we need to do in the Properties window is to make a preprocessor definition for SFML. So go to C/C++ >Preprocessor, and click “Edit…” under Preprocessor Definitions. We’re going to add “SFML_DYNAMIC” to our list and hit OK, and then OK to close the Properties window
There is just one last thing I want to briefly touch on. In the SFML lib directory, you will see there are a bunch of .dll files. It is imperative that you include these in the same directory as your program’s .exe or it will throw an error and fail to launch. I’ll go over these in more detail as we get to them, but I just want you to be aware for right now. 🙂
That’s all there is folks, everything is now set up and in my next post, we’ll use this to create a quick little demo program.
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
This one is going to be a long one, so I’m going to split it up. Everyone get their BLT’s ready and lets go.
Step 1 – Download and Install MS Visual Studio Express 2012: You can get it from here. Just grab either the installer or the full download and follow the on-screen instructions. Note that you may need to restart once or twice, and also, this can take a while to install.
Step 2 – Download Box2D: The Main page for Box2D can be found here or you can go straight to the download link here. This will grand you with a small zip file, extract it somewhere and keep a note of where it’s at, we’ll be using it in a little while.
Step 3 – SFML: You can get SFML from here, there are quite a few different versions that can be downloaded. The one you want is under C++ | version 1.6, I recommend that you grab the full SDK, not just the development files. While this will be about three times as large, it provides a bunch of nifty samples and their source files.
Next time, we’ll get Box2D installed and ready for use.
Welcome to the Autoblog, my rather hopeful attempt to educate both myself and others about some programming nonsense. I decided to create this blog because not too long ago I decided to delve into Box2D and wanted to do so for C++. The amount of online tutorials for Box2D is pretty extensive… if you want to use Flash, not so much so if you want to use it’s native language of C++.
So here we are, I am going to learn right along side all of you. What I will be presenting will be shown from a Windows perspective, using Visual Studio 2012 Express. Box2D will take care of our physics work, and for funsies I will also be using SFML as our rendering platform. So there you have it, in my next post I will be going over how to set everything up and we’ll be getting a quick little demo up and running. If you have or know of any other good tutorials for Box2D or SFML, I encourage you to leave it in the comments below!
And before I forget, these are also some pretty awesome tutorials that I’ve found very handy: