Introduction to openFrameworks

on the Raspberry Pi

Setting up the display

Everything should be all-right if you are using a regular HDMI display - Raspberry Pi should be able to detect monitors's native resolution autmatically.

In case you are using a HDMI to DVI adapter, you might need to adjust the monitor settings manually by editing the config.txt file on the Raspbian boot partition.

Here you can find available configuration options: http://elinux.org/RPiconfig#Video

Enter desktop mode

For the sake of simplicity, we are going to use the Raspberry Pi desktop mode. To enter it, type the following in the Raspberry Pi terminal:

startx

Press Enter and Raspberry Pi should transform in an almost normal desktop computer.

Get GEdit

In the Raspberry Pi Terminal type:

sudo apt-get install gedit

Press Enter to start the installation process. It might happen that the apt-get program asks you questions, press Y and Enter to proceed.

Test GEdit

To test if it works, type the name of the program (gedit) in the RPi Terminal:

gedit

Press Enter and a window with a text editor interface should open.

openFrameworks overview

As said in the openFrameworks website:

openFrameworks is an open source C++ toolkit for creative coding.


True it is...

Based on C++

openFrameworks is written in C++ and basically it is C++ with all it's pros and cons.

C++ pros

  • Very Fast
  • Well documented
  • A lot of available libraries

C++ cons

  • Not so easy to learn
  • Takes a long time to master

Learn C++

Don't be afraid! There are good C++ learning resources:

openFrameworks directory

If you followed the guide on the oF website, your openFrameworks directory should be located in your home directory: /home/pi. Enter it by typing in the RPi Terminal:

cd /home/pi/openFrameworks

Most important oF directories

  • apps
    This is the main directory for storing your work - code and compiled programs.
  • addons
    oF default and 3rd party addons that you can use in your programs.
  • examples
    Here you can find different openFrameworks examples. It's a good way to learn openFrameworks by exploring them.

apps directory

The apps directory contains categories of apps. There is one predefined category myApps already there.

Application directory

There are two main directories that should be in each openFrameworks project folder:

  • src
    for the source .h and .cpp files
  • bin
    for the compiled program files

File types

There are two basic file types:

  • .h
    or header files
  • .cpp
    or C++ files

Hands on

In the Pi Terminal type

cd /home/pi/openFrameworks/apps

and press Enter to go to your openFrameworks application directory.

Download examples using Git

In the Pi Terminal type

git clone https://github.com/kr15h/rpi-of-workshop-examples.git

press Enter. This will download the example projects of this workshop in rpi-of-workshop-examples within the openFrameworks apps directory.

Enter example directory

In the Pi Terminal type

cd rpi-of-workshop-examples

and press Enter.

Compile an example

Try to compile and run the examples by entering a project directory. Type

cd testApp

and press Enter to enter the testApp project directory. Type

make

and press Enter to compile. It will take some time, just wait.

Run an example

In Pi Terminal type

make run

and press Enter to open the testApp program. You can also type

./bin/testApp

to launch it as the compiled program file is located in the bin/ directory within the testApp project folder.

Try out other examples

Try to compile and run other examples by repeating the previous steps.

Addons

Some of the examples require 3rd party addons. Navigate to the addons folder by typing

cd /home/pi/openFrameworks/addons

and pressing Enter.

ofxTween addon

To install the ofxTween addon, type

git clone https://github.com/arturoc/ofxTween.git

press Enter and wait. ofxTween directory will be created in the openFrameworks addons folder.

ofxStateMachine addon

To install the ofxStateMachine addon, type

git clone https://github.com/neilmendoza/ofxStateMachine.git

press Enter and wait. ofxStateMachine directory will be created in the openFrameworks addons folder.

Other addons

Similarly you can install other addons if they are published on GitHub. If they are not, download the addon and place it in the openFrameworks/addons folder yourself.

Where to search for addons?

ofxaddons.com contains a lot of interesting addons that can be useful for your own projects. Note that all of them does not work on the Raspberry Pi, so be careful.

Using addons

You need to have a addons.make file in your project directory. Simply enter the folder name of the addon you want to use in the file, separate multiple addons with a newline:

ofxMidi
ofxOsc

Makefile

There has to be a Makefile in the project folder to be able to compile the project. If it is not there, copy it from some of the default projects like emptyExample:

cp ../emptyExample/Makefile ./