O'Reilly logo

openFrameworks Essentials by Denis Perevalov, Igor Tatarnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required