Box2D C++ tutorials - Setting up (Linux)

Last edited: May 11 2017

Building the testbed (Linux)

Let's look at the process of setting up the default 'testbed' which is part of the Box2d source code base. The testbed is a very useful tool which contains examples of various features which you can interact with using the mouse, adjust parameters, pause and step the simulation etc.

Here I am using a fresh install of Fedora 14, so I might as well start right from the very beginning.

The simplest way to build the Box2D library is to use the cmake file which is included in the source code download. To do this you will need the cmake tool, and obviously a c++ compiler. For the testbed you will also need the developer libraries for GLUT and an input library for X windows. You can use yum to install all these in one go, like this:
yum install gcc-c++ cmake freeglut-devel libXi-devel

sudo apt-get install g++ cmake libglu-dev libxi-dev
Download the Box2D source code archive from here. If you want to use the terminal all the way, you could also do this (if wget is not available, use yum to install it):
Use the following commands to unzip and build it.
(Update: See also david's comment below for Ubuntu
cd Box2D_v2.1.2/Box2D/Build
cmake ..
After this you should see that some new folders have been created, one of which is 'Testbed' and this in turn contains an executable file called 'Testbed', so the app can be started like this:
cd Testbed
You should see the testbed window showing like this:
Testbed Select from the drop-down list in the top right to try out the tests that are currently in the testbed. We will be adding our own items into this list later on.

Testbed features

Apart from the obvious features visible in the right hand control panel, the testbed also allows you to:
  • Move the view around - arrow keys or drag with right mouse button
  • Zoom the view - z,x keys
  • Grab objects in the scene - left mouse button
  • Launch a bomb into the scene from a random location - space bar
  • Launch a bullet into the scene - drag left mouse button while holding shift, then let go
Depending on which test you view, you can sometimes use the keyboard to interact with the scene too. We will make use of the mouse and keyboard interactions in these tutorials.