Book Image

OpenFrameworks Essentials

Book Image

OpenFrameworks Essentials

Overview of this book

Table of Contents (19 chapters)
openFrameworks Essentials
About the Authors
About the Reviewers


The ofApp class is the main class for the openFrameworks project. It is declared in the ofApp.h file, and its functions are defined in the ofApp.cpp file. It contains functions that are called by the openFrameworks engine on starting up, rendering, and various events from the user, such as mouse events and keyboard events. (See Chapter 2, Creating Your First openFrameworks Project, for details).

The most important functions that should be filled to have a working project are the following:

  • setup(): This is called by openFrameworks once on starting the application. For example, it can include the following commands:

    ofSetWindowTitle( "My project" );
    ofSetWindowShape( 1280, 720 );
    ofSetFrameRate( 60 );
    ofSetFullScreen( true );

    The first line sets the application's window title to My project. The second line sets the window size to a width of 1280 pixels and a height of 720 pixels. The third line sets the rendering frame rate to 60 frames per second. The last line enables the fullscreen mode.

  • update(): This is called for computations, such as processing the camera data.

  • draw(): This is called to perform drawing onscreen.

The update() and draw() functions are called repeatedly until the application is stopped.