Running your first example
We would like to introduce one of the funniest openFrameworks examples, which we like a lot. The example captures the images from a webcam and draws it on the screen as a fancy 3D surface, as shown in the following picture:
This is the meshFromCamera
example located in the examples/3d
folder.
Tip
This example requires a webcam. If your computer does not have a built-in webcam, and you have no external webcam to connect to, please work with another example, for instance, examples/3d/3DPrimitivesExample
.
We cannot run the example immediately after installing openFrameworks. The reason is that openFrameworks examples are distributed as source files only, without executable files that you can run.
To obtain the executable file, we need to build the project, that is, compile its C++ source code to machine code and link it into an executable file. Let's do it and then run the example by performing the following steps:
- Open the example folder
examples/3d/meshFromCamera
. - Find there the file named
meshFromCamera.xcodeproj
(Xcode project),meshFromCamera.sln
(Visual Studio project), ormeshFromCamera.workspace
(Code::Blocks project). - Double-click on this file, and the
meshFromCamera
project will open in your IDE. - Build the project by pressing Command + B in Xcode, F7 in Visual Studio, or by clicking on the Build button in Code::Blocks.
Tip
For Xcode users
In the project, there exist several schemes that indicate the part of the project to build and a number of settings for it. Often at first run, the scheme is set to openFrameworks, as shown on the following screenshot:
If so, the compiler builds openFrameworks, but not the project. To resolve the issue, please click on the scheme name. A context menu will appear. Select the meshFromCamera Release scheme there. After this, perform building as described in step 4.
- Run the project by clicking on the corresponding button in your IDE (normally, it's depicted as a small triangle, meaning the play symbol). After running, you will see your webcam's image drawn as a distorted 3D surface.
- Press Esc to stop the execution.
This example involves several topics, such as capturing frames from the camera, creating 3D surfaces, and texturing them. You will discover these topics in Chapter 4, Working with Raster Graphics – Images, Videos, and Shaders, and Chapter 5, Creating 3D Graphics, and will be able to build similar and even more sophisticated projects easily.