Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenFrameworks Essentials

You're reading from   OpenFrameworks Essentials Create stunning, interactive openFrameworks-based applications with this fast-paced guide

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher
ISBN-13 9781784396145
Length 206 pages
Edition 1st Edition
Arrow right icon
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with openFrameworks FREE CHAPTER 2. Creating Your First openFrameworks Project 3. Adding a GUI and Handling Keyboard Events 4. Working with Raster Graphics – Images, Videos, and Shaders 5. Creating 3D Graphics 6. Animating Parameters 7. Distributed and Physical Computing with Networking and Arduino 8. Deploying the Project on iOS, Android, and Raspberry Pi 9. Further Resources A. Video Synthesizer Reference B. openFrameworks Quick Reference 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(...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image