9780596804824
index.html

iPhone 3D Programming

Developing Graphical Applications with OpenGL ES

Philip Rideout

All rights reserved.

Abstract

Note

You are reading the text of an O'Reilly book that's under development. The author is publishing the book to this site as it's being written, and we're putting it here to get feedback from you. This book uses the Open Feedback Publishing System (OFPS), an O'Reilly experiment that tries to bridge the gap between private manuscripts and public blogs.

Next to every paragraph, there is a link you can use to comment on what you're reading. We are grateful for any feedback you have: questions, comments, suggestions, and corrections are all welcome and appreciated.

Learn more and preorder at the book's catalog page.

The sample code for this book is available at http://examples.oreilly.com/9780596804831/.


Dedication

Frank and Doris Rideout

1916-1998 and 1919-2007

Foreword
Preface
How to Read This Book
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgements
1. Quick Start Guide
Transitioning to Apple Technology
Objective-C
A Brief History of OpenGL ES
Choosing the Appropriate Version of OpenGL ES
Getting Started
Installing the iPhone SDK
Building the OpenGL Template Application with Xcode
Deploying to Your Real iPhone
Hello Arrow with Fixed Function
Layering Your 3D Application
Starting from Scratch
Linking in the OpenGL and Quartz Libraries
Subclassing UIView
Hooking Up the Application Delegate
Setting Up the Icons and Launch Image
Dealing with the Status Bar
Defining and Consuming the Rendering Engine Interface
Implementing the Rendering Engine
Handling Device Orientation
Animating the Rotation
Hello Arrow with Shaders
Shaders
Frameworks
GLView
RenderingEngine Implementation
Wrapping Up
2. Math and Metaphors
The Assembly Line Metaphor
Assembling Primitives from Vertices
Associating Properties with Vertices
The Life of a Vertex
The Photography Metaphor
Setting the Model Matrix
Setting the View Transform
Setting the Projection Transform
Saving and Restoring Transforms with Matrix Stacks
Animation
Interpolation Techniques
Animating Rotation with Quaternions
Vector Beautification with C++
Hello Cone with Fixed Function
RenderingEngine Declaration
OpenGL Initialization and Cone Tessellation
Smooth Rotation in Three Dimensions
Render Method
Hello Cone with Shaders
Wrapping Up
3. Vertices and Touch Points
Reading the Touch Screen
Saving Memory with Vertex Indexing
Boosting Performance with Vertex Buffer Objects
Creating a Wireframe Viewer
Parametric Surfaces for Fun
Designing the Interfaces
Handling Trackball Rotation
Implementing the Rendering Engine
Poor Man's Tab Bar
Animating the Transition
Wrapping Up
4. Adding Depth and Realism
Examining the Depth Buffer
Beware the Scourge of Depth Artifacts
Creating and Using the Depth Buffer
Filling the Wireframe with Triangles
Surface Normals
Feeding OpenGL with Normals
The Math Behind Normals
Normal Transforms Aren't Normal
Generating Normals from Parametric Surfaces
Lighting Up
Ho-Hum Ambiance
Matte Paint With Diffuse Lighting
Give it a Shine with Specular
Adding Light to Model Viewer
Using Light Properties
Shaders Demystified
Adding Shaders to Model Viewer
New Rendering Engine
Per-Pixel Lighting
Toon Shading
Better Wireframes using Polygon Offset
Loading Geometry From OBJ Files
Managing Resource Files
Implementing ISurface
Wrapping Up
5. Textures and Image Capture
Adding Textures to Model Viewer
Enhancing IResourceManager
Generating Texture Coordinates
Enabling Textures with ES1::RenderingEngine
Enabling Textures with ES2::RenderingEngine
Texture Coordinates Revisited
Fight Aliasing with Filtering
Boosting Quality and Performance with Mipmaps
Modifying Model Viewer to Support Mipmaps
Texture Formats and Types
Hands on: Loading Various Formats
Texture Compression with PVRTC
The PowerVR SDK and Low-Precision Textures
Generating and Transforming OpenGL Textures with Quartz
Dealing with Size Constraints
Scaling to POT
Creating Textures with the Camera
CameraTexture: Rendering Engine Implementation
Wrapping Up
6. Blending and Augmented Reality
Blending Recipe
Wrangle Pre-Multiplied Alpha
Blending Caveats
Blending Extensions and Their Uses
Why is Blending Configuration Useful?
Shifting Texture Color with Per-Vertex Color
Poor Man's Reflection with the Stencil Buffer
Rendering the Disk to Stencil Only
Rendering the Reflected Object with Stencil Testing
Rendering the "Real" Object
Rendering the Disk with Front-to-Back Blending
Stencil Alternatives for Older iPhones
Antialiasing Tricks with Offscreen FBOs
A Super Simple Sample App for Supersampling
Jittering
Other FBO Effects
Rendering Antialiased Lines with Textures
Holodeck Sample
Application Skeleton
Rendering the Dome, Clouds, and Text
Handling the Heads Up Display
Replacing Buttons with Orientation Sensors
Overlaying with a Live Camera Image
Wrapping Up
7. Sprites and Text
Text Rendering 101: Drawing a FPS Counter
Generating a Glyphs Texture with Python
Rendering the FPS Text
Simplify with glDrawTexOES
Crisper Text with Distance Fields
Generating Distance Fields with Python
Use Distance Fields under ES 1.1 with Alpha Testing
Adding Text Effects with Fragment Shaders
Smoothing and Derivatives
Implementing Outline, Glow, and Shadow Effects
Animation with Sprite Sheets
Image Composition and a Taste of Multitexturing
Mixing OpenGL ES and UIKit
Rendering Confetti, Fireworks, and More: Point Sprites
Chapter Finale: Springy Stars
Physics Diversion: Mass-Spring System
C++ Interfaces and GLView
ApplicationEngine Implementation
OpenGL ES 1.1 Rendering Engine and Additive Blending
Point Sprites with OpenGL ES 2.0
Wrapping Up
8. Advanced Lighting and Texturing
Texture Environments under OpenGL ES 1.1
Texture Combiners
Bump Mapping and Dot3 Lighting
Another Foray into Linear Algebra
Generating Basis Vectors
Normal Mapping with OpenGL ES 2.0
Normal Mapping with OpenGL ES 1.1
Generating Object-Space Normal Maps
Reflections With Cube Maps
Render to Cubemap
Anisotropic Filtering: Textures on Steroids
Image Processing Example: Bloom
Better Performance with a Hybrid Approach
Sample Code for Gaussian Bloom
Wrapping Up
9. Optimizing
Instruments
Understand the CPU/GPU Split
Vertex Submission: Above and Beyond VBOs
Batch, Batch, Batch
Interleaved Vertex Attributes
Optimize Your Vertex Format
Use the Best Topology and Indexing
Lighting Optimizations
Object Space Lighting
DOT3 Lighting Revisited
Baked Lighting
Texturing Optimizations
Culling and Clipping
Polygon Winding
User Clip Planes
CPU-Based Clipping
Shader Performance
Conditionals
Fragment Killing
Texture Lookups Can Hurt!
Optimizing Animation with Vertex Skinning
Skinning: Common Code
Skinning with OpenGL ES 2.0
Skinning with OpenGL ES 1.1
Generating Weights and Indices
Watch out for Pinching
Further Reading
A. C++ Vector Library
Disclaimer Regarding Performance
Vector.hpp
Matrix.hpp
Quaternion.hpp
Site last updated on: June 8, 2011 at 08:46:33 AM PDT