Tải bản đầy đủ (.pdf) (10 trang)

3D Graphics with OpenGL ES and M3G- P1 pps

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (659.4 KB, 10 trang )

Mobile 3D Graphics
with OpenGL ES and M3G
This page intentionally left blank
Mobile 3D Graphics
with OpenGL ES and M3G
Kari Pulli
Tomi Aarnio
Ville Miettinen
Kimmo Roimela
Jani Vaarala
AMSTERDAM

BOSTON

HEIDELBERG

LONDON
NEW YORK

OXFORD

PARIS

SAN DIEGO
SAN FRANCISCO

SINGAPORE

SYDNEY


TOKYO
Morgan Kaufmann is an imprint of Elsevier
Acquisitions Editor Tiffany Gasbarrini
Publishing Services Manager George Morrison
Senior Production Editor Paul Gottehrer
Cover Design Eric DeCicco
Composition diacriTech
Interior printer Maple-Vail Book Manufacturing Group
Cover printer Phoenix Color Corp.
Morgan Kaufmann Publishers is an imprint of Elsevier.
30 Corporate Drive, Suite 400, Burlington, MA 01803, USA
This book is printed on acid-free paper.
c
 2008 by Elsevier Inc. All rights reserved.
Designations used by companies to distinguish their products are often claimed as trademarks or
registered trademarks. In all instances in which Morgan Kaufmann Publishers is aware of a claim, the
product names appear in initial capital or all capital letters. Readers, however, should contact the
appropriate companies for more complete information regarding trademarks and registration.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means—electronic, mechanical, photocopying, scanning, or otherwise—without prior wr itten
permission of the publisher.
Permissions may be sought directly from Elsevier’s Science & Technology Rights Department in Oxford,
UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333, E-mail: permissions@elsev i er.com. You may
also complete your request online via the Elsevier homepage (), by selecting “Support
& Contact” then “Copyright and Permission” and then “Obtaining Permissions.”
Library of Congress Cataloging-in-Publication Data
Application submitted
ISBN: 978-0-12-373727-4
For information on all Morgan Kaufmann publications,
visit our We b site at www.mkp.com or www.books.elsevier.com

Printed in the United States of America
0708091011 54321
Contents
Preface xiii
About the Authors xv
CHAPTER 1. INTRODUCTION 1
1.1 About this Book 2
1.1.1 Typographic Conventions 3
1.2 Graphics on Handheld Devices 3
1.2.1 Device Categories 4
1.2.2 Display Technology 5
1.2.3 Processing Power 6
1.2.4 Graphics Hardware 8
1.2.5 Execution Environments 9
1.3 Mobile Graphics Standards 12
1.3.1 Fighting the Fragmentation 12
1.3.2 Design Principles 14
1.3.3 OpenGL ES 18
1.3.4 M3G 19
1.3.5 Related Standards 21
PART I ANATOMY OF A GRAPHICS ENGINE
CHAPTER 2. LINEAR ALGEBRA FOR 3D GRAPHICS 27
2.1 Coordinate Systems 27
2.1.1 Vectors and Points 29
2.1.2 Vector Products 29
2.1.3 Homogeneous Coordinates 31
2.2 Matrices 31
2.2.1 Matrix Products 32
2.2.2 Identity and Inverse 33
2.2.3 Compound Transformations 33

2.2.4 Transforming Normal Vectors 34
v
vi CONTENTS
2.3 Affine Transformations 35
2.3.1 Types of Affine Transformations 35
2.3.2 Transformation Around a Pivot 39
2.3.3 Example: Hierarchical Modeling 39
2.4 Eye Coordinate System 42
2.5 Projections 44
2.5.1 Near and Far Planes and the Depth Buffer 45
2.5.2 A General View Frustum 47
2.5.3 Parallel Projection 50
2.6 Viewport and 2D Coordinate Systems 51
CHAPTER 3. LOW-LEVEL RENDERING 55
3.1 Rendering Primitives 57
3.1.1 Geometric Primitives 57
3.1.2 Raster Primitives 60
3.2 Lighting 61
3.2.1 Color 61
3.2.2 Normal Vectors 63
3.2.3 Reflection Models and Materials 64
3.2.4 Lights 68
3.2.5 Full Lighting Equation 70
3.3 Culling and Clipping 70
3.3.1 Back-Face Culling 71
3.3.2 Clipping and View-Frustum Culling 71
3.4 Rasterization 73
3.4.1 Texture Mapping 74
3.4.2 Interpolating Gradients 82
3.4.3 Texture-Based Lighting 83

3.4.4 Fog 88
3.4.5 Antialiasing 90
3.5 Per-Fragment Operations 92
3.5.1 Fragment Tests 92
3.5.2 Blending 95
3.5.3 Dithering, Logical Operations, and Masking 99
3.6 Life Cycle of a Frame 100
3.6.1 Single versus Double Buffering 101
3.6.2 Complete Graphics System 101
3.6.3 Synchronization Points 102
CHAPTER 4. ANIMATION 105
4.1 Keyframe Animation 105
4.1.1 Interpolation 106
4.1.2 Quaternions 111
CONTENTS vii
4.2 Deforming Meshes 113
4.2.1 Morphing 113
4.2.2 Skinning 114
4.2.3 Other Dynamic Deformations 116
CHAPTER 5. SCENE MANAGEMENT 117
5.1 Triangle Meshes 118
5.2 Scene Graphs 120
5.2.1 Application Area 120
5.2.2 Spatial Data Structure 121
5.2.3 Content Creation 123
5.2.4 Extensibility 125
5.2.5 Class Hierarchy 125
5.3 Retained Mode Rendering 128
5.3.1 Setting Up the Camera and Lights 129
5.3.2 Resolving Rendering State 130

5.3.3 Finding Potentially Visible Objects 130
5.3.4 Sorting and Rendering 132
CHAPTER 6. PERFORMANCE AND SCALABILITY 133
6.1 Scalability 134
6.1.1 Special Effects 135
6.1.2 Tuning Down the Details 136
6.2 Performance Optimization 136
6.2.1 Pixel Pipeline 137
6.2.2 Vertex Pipeline 139
6.2.3 Application Code 140
6.2.4 Profiling OpenGL ES Based Applications 141
6.2.5 Checklists 142
6.3 Changing and Querying the State 145
6.3.1 Optimizing State Changes 146
6.4 Model Data 146
6.4.1 Ver tex Data 147
6.4.2 Triangle Data 148
6.5 Transformation Pipeline 148
6.5.1 Object Hierarchies 148
6.5.2 Rendering Order 149
6.5.3 Culling 150
6.6 Lighting 151
6.6.1 Precomputed Illumination 151
viii CONTENTS
6.7 Textures 152
6.7.1 Texture Storage 152
PART II OPENGL ES AND EGL
CHAPTER 7. INTRODUCING OPENGL ES 157
7.1 Khronos Group and OpenGL ES 157
7.2 Design Principles 158

7.3 Resources 159
7.3.1 Documentation 160
7.3.2 Technical Support 160
7.3.3 Implementations 160
7.4 API Overview 161
7.4.1 Profiles and Versions 161
7.4.2 OpenGL ES 1.0 in a Nutshell 161
7.4.3 New Features in OpenGL ES 1.1 164
7.4.4 Extension Mechanism 165
7.4.5 OpenGL ES Extension Pack 166
7.4.6 Utility APIs 166
7.4.7 Conventions 167
7.5 Hello, OpenGL ES! 170
CHAPTER 8. OPENGL ES TRANSFORMATION AND
LIGHTING
173
8.1 Drawing Primitives 173
8.1.1 Primitive Types 174
8.1.2 Specifying Vertex Data 177
8.1.3 Drawing the Primitives 179
8.1.4 Ver tex Buffer Objects 180
8.2 Vertex Transformation Pipeline 183
8.2.1 Matrices 183
8.2.2 Transforming Normals 185
8.2.3 Texture Coordinate Transformation 186
8.2.4 Matrix Stacks 188
8.2.5 Viewport Transformation 188
8.2.6 User Clip Planes 189
8.3 Colors and Lighting 189
8.3.1 Specifying Colors and Materials 189

8.3.2 Lights 190
8.3.3 Two-Sided Lighting 192
8.3.4 Shading 193
8.3.5 Lighting Example 193
CONTENTS ix
CHAPTER 9. OPENGL ES RASTERIZATION AND
FRAGMENT PROCESSING
195
9.1 Back-Face Culling 195
9.2 Texture Mapping 196
9.2.1 Texture Objects 196
9.2.2 Specifying Texture Data 197
9.2.3 Texture Filtering 202
9.2.4 Texture Wrap Modes 205
9.2.5 Basic Texture Functions 205
9.2.6 Multi-Texturing 206
9.2.7 Texture Combiners 207
9.2.8 Point Sprite Texturing 209
9.2.9 Implementation Differences 209
9.3 Fog 210
9.4 Antialiasing 211
9.4.1 Edge Antialiasing 211
9.4.2 Multisampling 212
9.4.3 Other Antialiasing Approaches 213
9.5 Pixel Tests 214
9.5.1 Scissoring 214
9.5.2 Alpha Test 214
9.5.3 Stencil Test 215
9.5.4 Depth Testing 218
9.6 Applying Fragments to the Color Buffer 218

9.6.1 Blending 219
9.6.2 Dithering 220
9.6.3 Logic Ops 220
9.6.4 Masking Frame Buffer Channels 220
CHAPTER 10. MISCELLANEOUS OPENGL ES FEATURES 223
10.1 Frame Buffer Operations 223
10.1.1 Clearing the Buffers 223
10.1.2 Reading Back the Color Buffer 224
10.1.3 Flushing the Command Stream 225
10.2 State Queries 225
10.2.1 Static State 226
10.2.2 Dynamic State Queries 227
10.3 Hints 233
10.4 Extensions 234
10.4.1 Querying Extensions 234
10.4.2 Query Matrix 234
10.4.3 Matrix Palette 235
10.4.4 Draw Texture 238
10.4.5 Using Extensions 238

×