Preface
openFrameworks is a simple and powerful C++ toolkit designed to develop real-time projects with focus on generating and processing graphics and sound. Nowadays, this is a popular platform for experiments in generative and sound art and creating interactive installations and audiovisual performances.
Mastering openFrameworks: Creative Coding Demystified covers programming openFrameworks 0.8.0 for Windows, Mac OS X, and Linux. It provides a complete introduction to openFrameworks, including installation, core capabilities, and addons. Advanced topics like shaders, computer vision, and depth cameras are also covered.
You will learn everything you need to know to create your own projects, ranging from simple generative art experiments to big interactive systems consisting of a number of computers, depth cameras, and projectors.
This book focuses on low-level data processing, which allows you to create really unique and cutting-edge works.
What this book covers
Chapter 1, openFrameworks Basics, covers installing openFrameworks, the structure of openFrameworks projects, and creating the pendulum-simulation project.
Chapter 2, Drawing in 2D, explains the basics of two-dimensional graphics, including drawing geometric primitives, working with colors and drawing in the offscreen buffer. It also contains a generative art example of using numerical instability for drawing.
Chapter 3, Building a Simple Particle System, teaches the basics of particle system modeling and drawing. By the end of this chapter, you will build a fully featured project that can be used as a sketch for further experiments with particles.
Chapter 4, Images and Textures, covers the principles of working with images, including loading images from file; rendering it on the screen with different sizes, color, and transparency; creating new images; and modifying existing images. It also touches the basics of image warping and video mapping.
Chapter 5, Working with Videos, covers basic and advanced topics on playing, layering, and processing videos, including playing video files, processing live video grabbed from a camera, and working with image sequences. This chapter contains an implementation of the slit-scan effect and a simple video synthesizer, which uses a screen-to-camera feedback loop to create vivid effects on prerecorded videos.
Chapter 6, Working with Sounds, explains how to play sound samples, synthesize new sounds, and get sounds from the microphone. It includes the project wherein we generate music using bouncing-ball simulation, the PWM synthesizer, and the image-to-sound transcoding. Finally, it teaches us how to use spectrum analysis for creating an audio-reactive visual project.
Chapter 7, Drawing in 3D, covers representing, modifying, and drawing 3D objects. It includes examples of drawing a sphere-shaped cloud of triangles, an oscillating surface, and a twisting 3D knot.
Chapter 8, Using Shaders, explains how to use fragment, vertex, and geometry shaders for creating 2D video effects and 3D object deformations.
Chapter 9, Computer Vision with OpenCV, teaches the basics of computer vision using the OpenCV library. It explains how to perform filtering and correct perspective distortions in images and how to look for motion areas and detect bright objects in the videos. It includes an advanced example of using optical flow for video morphing.
Chapter 10, Using Depth Cameras, covers using depth cameras in openFrameworks projects using the ofxOpenNI addon. It includes an example of the projector-camera interactive system, which lets us draw abstract images on the wall. The example can be used as a sketch for creating interactive walls, tables, and floors.
Chapter 11, Networking, covers how to use OSC and TCP protocols in your openFrameworks projects for creating distributed projects that run on several computers. It includes an image-streaming example.
Appendix A, Working with Addons, teaches the basic principles of addons, explains how to link addons to your projects, and discusses some of the most useful addons.
Appendix B, Perlin Noise, explains the principles of using Perlin noise, which is employed in many of the examples in the book.
What you need for this book
For working with this book's examples and creating your openFrameworks projects, you need a computer with the Windows, Mac OS X, or Linux operating system.
You will also need to install some development environment (Visual Studio C++ Express, Xcode, or Code::Blocks) and openFrameworks itself. In the first chapter of the book, you will find detailed instructions for installation. All required software are free.
Some examples can require additional equipment:
The video synthesizer example section in Chapter 5, Working with Videos, and the The streaming images example section in Chapter 11, Networking, need a webcam for grabbing live video. If you are using a laptop, it most probably has a built-in webcam.
The loop sampler example section in Chapter 6, Working with Sounds, needs a microphone. If you are using a laptop, it most probably has a built-in microphone.
The furry carpet example section in Chapter 8, Using Shaders, uses a geometry shader, and therefore needs a modern video card.
The Creating interactive surface section in Chapter 10, Using Depth Cameras, needs a depth camera like Microsoft Kinect, Asus Xtion, or PrimeSense Carmine. Having a projector would be ideal, but is not compulsory.
Who this book is for
If you are a visual artist, designer, or programmer interested in creative coding with openFrameworks, this book is for you. Basic knowledge of programming, such as C++, Java, Python, or ActionScript, would be helpful.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Now you can call setNormals( mesh )
and the normals will be computed."
A block of code is set as follows:
for ( int i=0; i<16; i++ ) { table[i] = ofRandom( 0, 255 ); }
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
for ( int i=0; i<16; i++ ) {
table[i] = ofRandom( 0, 255 );
}
Any command-line input or output is written as follows:
ping 192.168.0.3
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Go to http://www.codeblocks.org, click on the Downloads menu item, and click on Download the binary release."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <feedback@packtpub.com>
, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Downloading the color graphics PDF
For downloading the colored graphics of this book visit: http://www.packtpub.com/sites/default/files/downloads/8048OS_ColoredImages.pdf
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at <questions@packtpub.com>
if you are having a problem with any aspect of the book, and we will do our best to address it.