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
- oF Add Ons
- Other Handy Utility Functions and Classes
- Example Code to Study
- Example Sketch One - Mouse Trails
- Example Sketch Two - Twisted Squares
- Some Game Built using oF
- 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:
- π ofxGui - Handy parameter tweaking GUI with sliders, checkboxes, and buttons. π¦ Examples.
- π ofxBox2d - 2D physics engine that wraps Box2d. π¦ Examples.
- π ofxNetwork and ofxOSC - TCP, UPC, and OSC networking libraries. π¦ Examples.
- π ofxOpenCV - Wraps the powerful OpenCV computer vision library. π¦ Examples.
- π ofxSVG - Vector graphics loader for SVG files. π¦ Example.
- π ofxXMLSettings - Simple XML loader and saver. π¦ Example.
Resources
- πΊ Project Generator and Addons Tutorial - Lewis Lepton on YouTube (5m47s)
- π° Addon HowTo @ openframeworks.cc
Other Handy Utility Functions and Classes
Thereβs so much more to openFrameworks! Start by exploring these handy functions and classes:
- π
ofClamp()
- Clamp a value between a min and a max. - π
ofMap()
- Given a value and an input range, map the value to an output range. - π
ofRectangle
- Super handy for simple collision detection hit boxes. - π
ofDirectory
,ofFilePath
andofFile
- For working with files. - π
ofURLFileLoader
- For loading data from URLs. - π And many more!
Example Code to Study
Youβll find two example programs below, but there are lots of examples out there you can learn from:
- π¦ Official openFrameworks Examples - These are also found in the
examples
folder of the openFrameworks zip file. - π Cookbook of Common Tasks from ofAuckland.
- π¦ Example Source from Mastering openFrameworks Book.
- πΊ Lewis Leptonβs 76 Video openFrameworks YouTube series and π¦ the associated github repo.
- πΊ Dan Buzzoβs openFrameworks superBasics YouTube series and his many other playlists.
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.
- π Kings of Space by Block Games
- π Earth Analog and Hyper Train by Funcraft Games
- π Super Hexagon by Terry Cavanagh of VVVVVV fame - PC and mobile port of the original Flash Game.
- π Ridiculous Fishing - iOS game made with oF and ofxSpriteSheetRenderer.
- π Adventures of Yddar - Recent game jam game made with oF.
- π ofBook Chapter on making Experimental Games with oF
Other Important Links
- π openFrameworks Forums - Sign up today. :)
- π API Documentation @ openframeworks.cc
- π The ofBook @ openframeworks.cc
- π° How-Tos @ openframeworks.cc
- π¦ openFramworks Github Repo