Book Image

OpenFrameworks Essentials

Book Image

OpenFrameworks Essentials

Overview of this book

Table of Contents (19 chapters)
openFrameworks Essentials
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing a simple GUI panel with sliders


Let's create a simple GUI consisting of a panel and three sliders. The first thing required is to add the ofxGui addon to the project. Fortunately, we already did it when creating the project in the previous chapter (see step 4 (Selecting the addons) of the Creating a project section of Chapter 2, Creating Your First openFrameworks Project). Perform the following steps:

  1. Include the addon's header to the ofApp.h file by inserting the following line (after the #include "ofMain.h" line):

    #include "ofxGui.h"
  2. Next, declare the visual panel and four sliders by adding the following lines to the ofApp class' declaration:

    ofxPanel gui;
    ofxIntSlider countX;
    ofxFloatSlider stepX;
    ofxFloatSlider twistX;

    The first line declares the GUI panel, which will be a container for all our GUI elements. The second line declares the countX slider, which holds integer values. The last two lines declare the stepX and twistX sliders with float values.

    Tip

    The gui, countX, stepX...