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

Drawing an image file


Let's load an image file and draw it on the screen. We will not want to change the pixel values, so we will use the ofTexture class for this task. Perform the following steps:

  1. Add the image object definition to the ofApp class:

    ofTexture image;
  2. Add the command for loading the image from the collage.png file to setup():

    ofLoadImage( image, "collage.png" );
  3. At the beginning of the draw() function, right after the ofBackground... command, add the code for drawing the image:

    ofSetColor( 255 );
    image.draw( 0, 0, ofGetWidth(), ofGetHeight() );

    The first line sets up the white drawing color, which serves here as an image drawing color (see the details about the ofSetColor function in Chapter 2, Creating Your First openFrameworks Project). By setting the color to white, we are guaranteed that the image will be drawn without color change.

    Note

    Setting another color will lead to changing the appearance of the image on the screen. For example, if we use the ofSetColor( 0, 255, 0 ) command...