Further Reading

We’ve only just scratched the surface of what is possible using openFrameworks. This section includes two sample projects, information about oF addons, and links to all sorts of example code.

Table of Contents

  1. oF Add Ons
  2. Other Handy Utility Functions and Classes
  3. Example Code to Study
  4. Example Sketch One - Mouse Trails
  5. Example Sketch Two - Twisted Squares
  6. Some Game Built using oF
  7. Other Important Links

oF Add Ons

openFramworks comes packaged with a number of addons that add extra functionality to the toolkit. A large number of community supported addons are also available through ofxaddons.com.

The included addons can be found in the addons folder. Any community addons you wish to use should be added to this folder.

Addons can be added to new or existing projects using the project generator app.

A few of the included addons:

Resources

Other Handy Utility Functions and Classes

There’s so much more to openFrameworks! Start by exploring these handy functions and classes:

Example Code to Study

You’ll find two example programs below, but there are lots of examples out there you can learn from:

Example Sketch One - Mouse Trails

Manually clearing the background with an alpha channel to create some mouse trails:

void ofApp::setup() {
    ofSetBackgroundAuto(false); // Disable automatic background clearing.
    ofEnableAlphaBlending();    // Allow alpha channel transparency.
    ofSetCircleResolution(50);  // Make circles smoother than the default.
    ofSetFrameRate(60);         // Set the framerate to 60 frames per second.
}

void ofApp::draw() {
    ofSetColor(0, 0, 0, 10); // Set the fill color to black with a low alpha value.
    ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); // Draw a rectangle that covers the canvas.
    ofSetColor(255, 255, 255, 255); // Set the fill color to white with full alpha.
    ofDrawCircle(ofGetMouseX(), ofGetMouseY(), 30); // Draw circle at the mouse position.
}

Example Sketch Two - Twisted Squares

Scaling and rotation of a circle controlled by the mouse position:

void ofApp::setup() {
    ofSetFrameRate(60); // Set frame rate to 60 FPS.
    ofSetRectMode(OF_RECTMODE_CENTER); // Rectangle x/y positions specify the shape's center.
    ofNoFill(); // Don't fill shapes.
}

void ofApp::draw() {
    // Pink and blue circular background gradient.
    ofBackgroundGradient(ofColor::deepPink, ofColor::deepSkyBlue, OF_GRADIENT_CIRCULAR);

    // Translate the coordinate system to the middle of the canvas.
    ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);

    // Map the mouse x position to a 0 to 20 range.
    double rotation = ofMap(ofGetMouseX(), 0, ofGetWidth(), 0, 20);
    // Map the mouse y position to a 1 to 1.2 range.
    double scaleFactor = ofMap(ofGetMouseY(), 0, ofGetHeight(), 1, 1.2);

    // Draw 100 squares of increasing size and rotation.
    for (auto i = 0; i < 100; ++i) {
        // The x position of the mouse mapped 0-20 sets the rotation.
        ofRotateZDeg(rotation);
        // The y position of the mouse mapped 1.0-1.2 sets the scaling.
        ofScale(scaleFactor, scaleFactor);
        // Draw the rotated and scaled square.
        ofDrawRectangle(0, 0, 1, 1);
    }
}

Some Game Built using oF

Although openFrameworks isn’t a game engine, it has been used for a some PC and mobile games.