Chapter 13. Graphics: Quartz, Core Animation, and OpenGL

 

This chapter covers

  • Using Quartz 2D for drawing
  • Understanding context, paths, and state
  • Using Core Animation
  • Learning about OpenGL ES

As you saw in chapter 11, creating and displaying images often isn’t enough. In games and other more complex programs, you’ll also want to manipulate those images in various ways at runtime. The iPhone OS offers two major ways to do this.

The first is through Quartz 2D, a two-dimensional drawing library that allows for complex line drawings, much as Canvas did on the web. It’s also the heart of the Core Graphics frameworks. We already touched on Quartz in the previous chapter, when you drew images straight to the CALayer of a UIView; it will be the focus of the majority of this chapter. Quartz also supports Core Animation functions, which we’ll address somewhat more briefly.

The second major way to manipulate images is through the OpenGL ES API. This cross-platform API, originally developed by Silicon Graphics, could be the topic of its own book, so we’ll only show you how to get started with it.

But most of this chapter will be about Quartz. We’ll look at drawing paths, setting the graphical state, and more advanced drawing techniques. We’ll dive into Quartz immediately.

13.1. An introduction to Quartz 2D

Quartz 2D is a two-dimensional drawing library that’s tightly integrated into the iPhone OS. It works well with all the relevant frameworks, including Core Animation, OpenGL ES, and the UIKit.

13.2. The Quartz context

13.3. Drawing paths

13.4. Setting the graphical state

13.5. Advanced drawing in Quartz

13.6. Drawing on a picture: an example

13.7. An introduction to Core Animation

13.8. An introduction to OpenGL

13.9. Summary