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

Mixing 2D and 3D with the GUI


Let's create two sliders and use them to mix 2D and 3D graphics using the following steps:

  1. Declare a new slider and a new offscreen buffer for storing the sphere image in the ofApp class:

    ofxFloatSlider show2d, show3d;
    ofFbo fbo3d;
  2. Add commands to set up sliders and the offscreen buffer to setup(), after the mixerGroup.add( ky.setup... command:

    mixerGroup.add( show2d.setup("show2d", 255, 0, 255) );
    mixerGroup.add( show3d.setup("show3d", 255, 0, 255) );
    fbo3d.allocate( ofGetWidth(), ofGetHeight(), GL_RGBA );

    The first and second lines set sliders to have a range from 0 to 255 and add them to the GUI group mixerGroup (this group was created in the previous chapter). The third line allocates the offscreen buffer with size equal to the screen size. We set the GL_RGBA pixel format for this buffer, so it will hold the pixels colors together with the alpha channel. Such a format is required here to properly mix fbo3d contents with fbo2 contents using the alpha blending...