Book Image

Mastering openFrameworks: Creative Coding Demystified

By : Denis Perevalov
Book Image

Mastering openFrameworks: Creative Coding Demystified

By: Denis Perevalov

Overview of this book

openFrameworks is a powerful programming toolkit and library designed to assist the creative process through simplicity and intuitiveness. It's a very handy software library written in C++ to reduce the software development process, helping you to kick-start creative coding. With the help of C++ and shaders support, openFrameworks allows for the processing of all kinds of media information with your custom-developed algorithms at the lowest possible level, with the fastest speed. "Mastering openFrameworks: Creative Coding Demystified" will introduce you to a world of creative coding projects, including interactive installations, audio-visual, and sound art projects. You will learn how to make your own projects using openFrameworks. This book focuses on low-level data processing, which allows you to create really unique and cutting-edge installations and projects. "Mastering openFrameworks: Creative Coding Demystified" provides a complete introduction to openFrameworks, including installation, core capabilities, and addons. Advanced topics like shaders, computer vision, and depth cameras are also covered. We start off by discussing the basic topics such as image and video loading, rendering and processing, playing sound samples, and synthesizing new sounds. We then move on to cover 3D graphics, computer vision, and depth cameras. You will also learn a number of advanced topics such as video mapping, interactive floors and walls, video morphing, networking, and using geometry shaders. You will learn everything you need to know in order to create your own projects; create projects of all levels, ranging from simple creative-code experiments, to big interactive systems consisting of a number of computers, depth cameras, and projectors.
Table of Contents (22 chapters)
Mastering openFrameworks: Creative Coding Demystified
Credits
Foreword
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Addons basics


Though openFrameworks' core has powerful capabilities for processing and generating various kinds of multimedia data, it does not contain everything. For example, the core does not contain support for depth cameras, processing the images using the computer vision library OpenCV, or sending and receiving data via a network.

For using such capabilities in your project, you would link and use any of the C++ or C external libraries that are available on the Internet. But, each library is different so using them in your project is sometimes easy and sometimes not. Fortunately, openFrameworks has a friendly mechanism for plugging libraries to your project. Such a mechanism is called an addon.

Most often, an addon is a class that acts as a wrapper for a library. Also, the addon contains the library itself in a form that is ready to be linked to your project binaries. This relation is shown in the following image:

The term wrapper here means that it lets your project and a library communicate in some way. openFrameworks' addon mission is to simplify such a communication and do it in a standardized way (in "the openFrameworks's style"). Hence, you do not need to learn about a library interface and its usage but just learn how to use an addon, and that would be enough for most situations. So using addons accelerates project development a lot. Furthermore, when you need deeper capabilities of the library, not included in the addon, you can always access them by reaching the library objects and functions directly or through the addon's class members.

Remember, an addon is just an openFrameworks extension; it only links to a project, which is using it, but does not affect the other projects and openFrameworks itself.

Sometimes an addon is not a wrapper, but just a class that adds some new functionality without linking any new library to the project. See the following image:

Addons in openFrameworks

Every openFrameworks's addon class name begins with ofx. This is an acronym for openFrameworks extension. For example, ofxXmlSettings is a class for writing and reading settings in XML files.

Addons are located in the addons folder of openFrameworks. The examples of addons' usage are located in the examples/addons folder of openFrameworks.

There are two classes of addons. The first class of addons is called core addons and is distributed with openFrameworks. You have the addons of this class in the addons folder right after installing openFrameworks. They are stable and useful addons that are needed in many interactive projects.

The second class of addons is called non-core addons and are available for download at http://ofxaddons.com. There are both mature addons as well as the ones currently in development. Please test them carefully before using them in your installations or performances. Fortunately, all the addons have open code, and you can always check and modify them. Nevertheless, sometimes addons have binary .lib or .a files; it is very difficult to find and correct errors in such addons rapidly, so again, test addons before using them.

Installing a non-core addon

To install a non-core addon into openFrameworks, perform the following steps:

  1. Go to http://ofxaddons.com, find the desired addon and click on its name.

  2. The addon's page will be opened. The page contains addon's description and downloading button. Currently download button is named Download ZIP and is located in the right part of the page. Press it to download the addon's archive.

  3. Unpack it into the openFrameworks' addons folder.

  4. If the name of the unpacked folder containing an addon does not match the addon's name, for example, ofxOpenNI-master.zip, rename the folder to the addon's name, ofxOpenNI.

  5. If the addon's folder contains examples of its usage, it is a good idea to move the examples to the examples/addons folder.

The world of addons is rapidly evolving. New addons appear and are renamed regularly. The most useful non-core addons eventually become core addons. And some core addons migrate into openFrameworks core. (Then the ofx prefix in the class name turns into of). So, it would not make much sense to discuss all the existing addons because next year, the list could be totally outdated. Nevertheless, we will discuss the current core and some non-core addons in the List of selected addons section.

Tip

Adding new capabilities to your projects using addons is very easy and comfortable. But there are many libraries and algorithms that have not been implemented in addons yet. So if your project needs some functionality, and if there are no addons for this, don't be upset and solve the problem without addons. For example, if you need to control a new device from your project, then find its SDK, the library or example of its usage, and use it in your C++ project directly without addons.

Once you succeed in doing this, you can package your code as an addon and publish it for the openFrameworks' community by following the recommendations at http://www.ofxaddons.com/howto/.

Now we will talk about linking addons to your project.