You are on page 1of 53

Computer Graphics Through OpenGL:

From Theory to Experiments Sumanta


Guha
Visit to download the full and correct content document:
https://textbookfull.com/product/computer-graphics-through-opengl-from-theory-to-ex
periments-sumanta-guha/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Computer graphics through openGL Third Edition Guha

https://textbookfull.com/product/computer-graphics-through-
opengl-third-edition-guha/

Computer Graphics Programming in OpenGL with Java


Gordon

https://textbookfull.com/product/computer-graphics-programming-
in-opengl-with-java-gordon/

Introduction to Computer Graphics with OpenGL ES First


Edition Junghyun Han

https://textbookfull.com/product/introduction-to-computer-
graphics-with-opengl-es-first-edition-junghyun-han/

Computer Graphics Programming in OpenGL Using C++,


Third Edition Gordon Phd

https://textbookfull.com/product/computer-graphics-programming-
in-opengl-using-c-third-edition-gordon-phd/
Computer Graphics Programming in OpenGL with Java 2nd
Edition V. Scott Gordon

https://textbookfull.com/product/computer-graphics-programming-
in-opengl-with-java-2nd-edition-v-scott-gordon/

Computer Graphics from Scratch 1st Edition Gabriel


Gambetta

https://textbookfull.com/product/computer-graphics-from-
scratch-1st-edition-gabriel-gambetta/

Learn OpenGL Learn modern OpenGL graphics programming


in a step by step fashion 1st Edition Joey De Vries

https://textbookfull.com/product/learn-opengl-learn-modern-
opengl-graphics-programming-in-a-step-by-step-fashion-1st-
edition-joey-de-vries/

Fundamentals of Computer Graphics Steve Marschner

https://textbookfull.com/product/fundamentals-of-computer-
graphics-steve-marschner/

Mathematics for Computer Graphics John Vince

https://textbookfull.com/product/mathematics-for-computer-
graphics-john-vince/
Computer Graphics Through OpenGL
From Theory to Experiments
Third Edition
Computer Graphics Through OpenGL
From Theory to Experiments
Third Edition

Sumanta Guha
Asian Institute of Technology, Thailand
Cover Designed by Sumanta Guha

CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742

© 2019 by Taylor & Francis Group, LLC


CRC Press is an imprint of Taylor & Francis Group, an Informa business

No claim to original U.S. Government works

Printed on acid-free paper


Version Date: 20181022

International Standard Book Number-13: 978-1-138-61264-8 (Hardback)

This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and
information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and
publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission
to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any
future reprint.

Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic,
mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or
retrieval system, without written permission from the publishers.

For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.copyright.com/) or contact
the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides
licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment
has been arranged.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation
without intent to infringe.

Library of Congress Cataloging-in-Publication Data

Names: Guha, Sumanta,


author.
Title: Computer graphics through openGL / Sumanta Guha.
Description: Third edition. | Boca Raton : Taylor & Francis, a CRC title,
part of the Taylor & Francis imprint, a member of the Taylor & Francis
Group, the academic division of T&F Informa, plc, 2018. | Includes
bibliographical references and index.
Identifiers: LCCN 2018027365 | ISBN 9781138612648 (hardback : acid-free paper)
Subjects: LCSH: Computer graphics. | Microcomputers--Programming. | OpenGL. |
BISAC: COMPUTERS / Computer Graphics. | MATHEMATICS / General.
Classification: LCC T385 .G85 2018 | DDC 006.6/633--dc23
LC record available at https://lccn.loc.gov/2018027365

Visit the Taylor & Francis Web site at


http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
To my parents Utpal Chandra and
Santa Guha and to Kamaladi
Contents

P REFACE XVII

A BOUT THE AUTHOR XXVII

I Hello World 1
1 A N I NVITATION TO C OMPUTER G RAPHICS 3
1.1 Brief History of Computer Graphics . . . . . . . . . . . . . . . . . . . 5
1.2 Overview of a Graphics System . . . . . . . . . . . . . . . . . . . . . . 8
1.2.1 Input Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.2 Output Devices . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.3 Quick Preview of the Adventures Ahead . . . . . . . . . . . . . . . . . 14

2 O N TO O PEN GL AND 3D C OMPUTER G RAPHICS 17


2.1 First Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.2 Orthographic Projection, Viewing Box and World Coordinates . . . . 19
2.3 The OpenGL Window and Screen Coordinates . . . . . . . . . . . . . 24
2.4 Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.5 Color, OpenGL State Machine and Interpolation . . . . . . . . . . . . 26
2.6 OpenGL Geometric Primitives . . . . . . . . . . . . . . . . . . . . . . 29
2.7 Approximating Curved Objects . . . . . . . . . . . . . . . . . . . . . . 35
2.8 Three Dimensions, the Depth Buffer and Perspective Projection . . . . 37
2.8.1 A Vital 3D Utility: The Depth Buffer . . . . . . . . . . . . . . 38
2.8.2 A Helix and Perspective Projection . . . . . . . . . . . . . . . 40
2.9 Drawing Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.10 Approximating Curved Objects Once More . . . . . . . . . . . . . . . 46
2.11 An OpenGL Program End to End . . . . . . . . . . . . . . . . . . . . 49
2.12 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 51

II Tricks of the Trade 53


3 A N O PEN GL T OOLBOX 55
3.1 Vertex Arrays and Their Drawing Commands . . . . . . . . . . . . . . 56
3.2 Vertex Buffer Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
3.3 Vertex Array Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.4 Display Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 vii
CONTENTS 3.5 Drawing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.6 Programming the Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . 67
3.7 Programming Non-ASCII Keys . . . . . . . . . . . . . . . . . . . . . . 69
3.8 Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.9 Line Stipples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.10 FreeGLUT Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.11 Clipping Planes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.12 Frustum, Differently . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.13 Viewports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.14 Multiple Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.15 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 78

III Movers and Shapers 79


4 T RANSFORMATION , A NIMATION AND V IEWING 81
4.1 Modeling Transformations . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.1.1 Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.1.2 Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.1.3 Rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.2 Composing Modeling Transformations . . . . . . . . . . . . . . . . . . 88
4.3 Placing Multiple Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.4 Modelview Matrix Stack and Isolating Transformations . . . . . . . . 101
4.5 Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
4.5.1 Animation Technicals . . . . . . . . . . . . . . . . . . . . . . . 103
4.5.2 Animation Code . . . . . . . . . . . . . . . . . . . . . . . . . . 106
4.5.3 Animation Projects . . . . . . . . . . . . . . . . . . . . . . . . 115
4.6 Viewing Transformation . . . . . . . . . . . . . . . . . . . . . . . . . . 117
4.6.1 Understanding the Viewing Transformation . . . . . . . . . . . 117
4.6.2 Simulating a Viewing Transformation with Modeling Transfor-
mations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
4.6.3 Orientation and Euler Angles . . . . . . . . . . . . . . . . . . . 130
4.6.4 Viewing Transformation and Collision Detection in Animation 133
4.7 More Animation Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
4.7.1 Animating an Articulated Figure . . . . . . . . . . . . . . . . 136
4.7.2 Simple Orthographic Shadows . . . . . . . . . . . . . . . . . . 138
4.8 Selection and Picking . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
4.8.1 Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
4.8.2 Picking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
4.9 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 145

5 I NSIDE A NIMATION : T HE T HEORY OF T RANSFORMATIONS 147


5.1 Geometric Transformations in 2-Space . . . . . . . . . . . . . . . . . . 148
5.1.1 Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
5.1.2 Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
5.1.3 Rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
5.1.4 Reflection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
5.2 Affine Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
5.2.1 Affine Transformations Defined . . . . . . . . . . . . . . . . . . 154
5.2.2 Affine Transformations and OpenGL . . . . . . . . . . . . . . 158
5.2.3 Affine Transformations and Homogeneous Coordinates . . . . 160
viii 5.3 Geometric Transformations in 2-Space Continued . . . . . . . . . . . . 162
5.3.1 Affine Geometric Transformations . . . . . . . . . . . . . . . . 162 CONTENTS
5.3.2 Euclidean and Rigid Transformations . . . . . . . . . . . . . . 166
5.4 Geometric Transformations in 3-Space . . . . . . . . . . . . . . . . . . 173
5.4.1 Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
5.4.2 Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
5.4.3 Rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
5.4.4 Reflection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
5.4.5 Affine Geometric Transformations . . . . . . . . . . . . . . . . 187
5.4.6 Accessing and Manipulating the Current Modelview Matrix . 189
5.4.7 Euclidean and Rigid Transformations . . . . . . . . . . . . . . 191
5.5 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 196

6 A DVANCED A NIMATION T ECHNIQUES 197


6.1 Frustum Culling by Space Partitioning . . . . . . . . . . . . . . . . . . 197
6.1.1 Space Partitioning . . . . . . . . . . . . . . . . . . . . . . . . . 199
6.1.2 Quadtrees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
6.1.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 201
6.1.4 More about Space Partitioning . . . . . . . . . . . . . . . . . . 202
6.2 Occlusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
6.2.1 Querying and Culling . . . . . . . . . . . . . . . . . . . . . . . 202
6.2.2 Conditional Rendering . . . . . . . . . . . . . . . . . . . . . . 205
6.3 Timer Queries and Performance Measurememt . . . . . . . . . . . . . 205
6.4 Animating Orientation Using Euler Angles . . . . . . . . . . . . . . . . 206
6.4.1 Euler Angles and the Orientation of a Rigid Body . . . . . . . 206
6.4.2 Animating Orientation . . . . . . . . . . . . . . . . . . . . . . 207
6.4.3 Problems with Euler Angles: Gimbal Lock and Ambiguity . . 208
6.5 Quaternions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
6.5.1 Quaternion Math 101 . . . . . . . . . . . . . . . . . . . . . . . 210
6.5.2 Quaternions and Orientation . . . . . . . . . . . . . . . . . . . 213
6.6 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 221

IV Geometry for the Home Office 223


7 C ONVEXITY AND I NTERPOLATION 225
7.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
7.2 Convex Combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
7.3 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
7.4 Convexity and the Convex Hull . . . . . . . . . . . . . . . . . . . . . . 234
7.5 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 239

8 T RIANGULATION 241
8.1 Definition and Justification . . . . . . . . . . . . . . . . . . . . . . . . 241
8.2 Steiner Vertices and the Quality of a Triangulation . . . . . . . . . . . 244
8.3 Triangulation in OpenGL and the Trouble with Non-Convexity . . . . 245
8.4 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 248

9 O RIENTATION 249
9.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
9.2 OpenGL Procedure to Determine Front and Back Faces . . . . . . . . 250
9.3 Consistently Oriented Triangulation . . . . . . . . . . . . . . . . . . . 255
9.4 Culling Obscured Faces . . . . . . . . . . . . . . . . . . . . . . . . . . 259
9.5 Transformations and the Orientation of Geometric Primitives . . . . . 261 ix
CONTENTS 9.6 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 262

V Making Things Up 263


10 M ODELING IN 3D S PACE 265
10.1 Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
10.1.1 Specifying Plane Curves . . . . . . . . . . . . . . . . . . . . . 266
10.1.2 Specifying Space Curves . . . . . . . . . . . . . . . . . . . . . 269
10.1.3 Drawing Curves . . . . . . . . . . . . . . . . . . . . . . . . . . 271
10.1.4 Polynomial and Rational Parametrizations . . . . . . . . . . . 274
10.1.5 Conic Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
10.1.6 Curves More Formally . . . . . . . . . . . . . . . . . . . . . . . 277
10.2 Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
10.2.1 Polygons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
10.2.2 Meshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
10.2.3 Planar Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . 285
10.2.4 General Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . 286
10.2.5 Drawing General Surfaces . . . . . . . . . . . . . . . . . . . . . 287
10.2.6 Swept Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
10.2.7 Drawing Projects . . . . . . . . . . . . . . . . . . . . . . . . . 296
10.2.8 Ruled Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
10.2.9 Quadric Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . 299
10.2.10 GLU Quadric Objects . . . . . . . . . . . . . . . . . . . . . . . 301
10.2.11 Regular Polyhedra . . . . . . . . . . . . . . . . . . . . . . . . . 303
10.2.12 Surfaces More Formally . . . . . . . . . . . . . . . . . . . . . . 307
10.3 Bézier Phrase Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
10.3.1 Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
10.3.2 Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
10.4 Importing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
10.5 Fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
10.6 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 324

VI Lights, Camera, Equation 327


11 C OLOR AND L IGHT 329
11.1 Vision and Color Models . . . . . . . . . . . . . . . . . . . . . . . . . . 330
11.1.1 RGB Color Model . . . . . . . . . . . . . . . . . . . . . . . . . 331
11.1.2 CMY and CMYK Color Models . . . . . . . . . . . . . . . . . 333
11.1.3 HSV (or HSB) Color Model . . . . . . . . . . . . . . . . . . . 334
11.1.4 Summary of the Models . . . . . . . . . . . . . . . . . . . . . . 334
11.2 Phong’s Lighting Model . . . . . . . . . . . . . . . . . . . . . . . . . . 335
11.2.1 Phong Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
11.2.2 Specifying Light and Material Values . . . . . . . . . . . . . . 337
11.2.3 Calculating the Reflected Light . . . . . . . . . . . . . . . . . 337
11.2.4 First Lighting Equation . . . . . . . . . . . . . . . . . . . . . . 342
11.3 OpenGL Light and Material Properties . . . . . . . . . . . . . . . . . 344
11.3.1 Light Properties . . . . . . . . . . . . . . . . . . . . . . . . . . 345
11.3.2 Material Properties . . . . . . . . . . . . . . . . . . . . . . . . 346
11.3.3 Experimenting with Properties . . . . . . . . . . . . . . . . . . 347
11.3.4 Color Material Mode . . . . . . . . . . . . . . . . . . . . . . . 350
11.4 OpenGL Lighting Model . . . . . . . . . . . . . . . . . . . . . . . . . . 351
x 11.5 Directional Lights, Positional Lights and Attenuation of Intensity . . . 353
11.6 Spotlights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 CONTENTS
11.7 OpenGL Lighting Equation . . . . . . . . . . . . . . . . . . . . . . . . 356
11.8 OpenGL Shading Models . . . . . . . . . . . . . . . . . . . . . . . . . 357
11.9 Animating Light . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
11.10 Partial Derivatives, Tangent Planes and Normal Vectors 101 . . . . . 358
11.11 Computing Normals and Lighting Surfaces . . . . . . . . . . . . . . . 365
11.11.1 Polygons and Planar Surfaces . . . . . . . . . . . . . . . . . . 365
11.11.2 Meshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
11.11.3 General Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . 368
11.11.4 FreeGLUT, Bézier and Quadric Surfaces . . . . . . . . . . . . 371
11.11.5 Transforming Normals . . . . . . . . . . . . . . . . . . . . . . 373
11.11.6 Normalizing Normals . . . . . . . . . . . . . . . . . . . . . . . 375
11.12 Phong’s Shading Model . . . . . . . . . . . . . . . . . . . . . . . . . . 375
11.13 Lighting Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
11.14 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . 378

12 T EXTURE 379
12.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
12.2 Texture Space, Coordinates and Map . . . . . . . . . . . . . . . . . . . 382
12.3 Repeating and Clamping . . . . . . . . . . . . . . . . . . . . . . . . . . 385
12.4 Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
12.5 Specifying the Texture Map . . . . . . . . . . . . . . . . . . . . . . . . 393
12.5.1 Parametrized Surfaces . . . . . . . . . . . . . . . . . . . . . . . 393
12.5.2 Bézier and Quadric Surfaces . . . . . . . . . . . . . . . . . . . 394
12.5.3 Spheres and Mercator Projection . . . . . . . . . . . . . . . . . 395
12.6 Texture Matrix and Animating Textures . . . . . . . . . . . . . . . . . 397
12.7 Lighting Textures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
12.8 Multitexturing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
12.9 Rendering to Texture with Framebuffer Objects . . . . . . . . . . . . . 401
12.10 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . 405

13 S PECIAL V ISUAL T ECHNIQUES 407


13.1 Blending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
13.1.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
13.1.2 Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
13.1.3 Opaque and Translucent Objects Together . . . . . . . . . . . 412
13.1.4 Blending Textures . . . . . . . . . . . . . . . . . . . . . . . . . 414
13.1.5 Creating Reflections . . . . . . . . . . . . . . . . . . . . . . . . 415
13.1.6 Motion Blur in World Space . . . . . . . . . . . . . . . . . . . 416
13.2 Fog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
13.3 Billboarding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
13.4 Antialiasing Points and Lines, Multisampling Polygons . . . . . . . . . 419
13.4.1 Antialiasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
13.4.2 Multisampling . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
13.5 Point Sprites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
13.6 Environment Mapping: Sphere Mapping and Cube Mapping . . . . . . 422
13.6.1 Sphere Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . 423
13.6.2 Cube Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
13.7 Stencil Buffer Techniques . . . . . . . . . . . . . . . . . . . . . . . . . 429
13.7.1 OpenGL Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . 429
13.7.2 Using the Stencil Buffer . . . . . . . . . . . . . . . . . . . . . . 430
13.8 Image Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434 xi
CONTENTS 13.9 Bump Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
13.10 Shadow Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
13.11 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . 442

VII Pixels, Pixels, Everywhere 443


14 R ASTER A LGORITHMS 445
14.1 Cohen-Sutherland Line Clipper . . . . . . . . . . . . . . . . . . . . . . 445
14.2 Sutherland-Hodgman Polygon Clipper . . . . . . . . . . . . . . . . . . 449
14.3 DDA and Bresenham’s Line Rasterizers . . . . . . . . . . . . . . . . . 451
14.4 Scan-Based Polygon Rasterizer . . . . . . . . . . . . . . . . . . . . . . 456
14.4.1 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
14.4.2 Optimizing Using Edge Coherence – Active Edge List . . . . . 462
14.5 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 466

VIII Programming Pipe Dreams 467


15 O PEN GL 4.3, S HADERS AND THE P ROGRAMMABLE P IPELINE : L IFT -
OFF 469
15.1 New Pipeline for OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . 470
15.1.1 Shaders in the Rendering Pipeline . . . . . . . . . . . . . . . . 470
15.1.2 New OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
15.2 GLSL Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
15.3 First Core GL 4.3 Program (Dissected) . . . . . . . . . . . . . . . . . 476
15.4 Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
15.5 Lighting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
15.5.1 Per-Vertex Lighting . . . . . . . . . . . . . . . . . . . . . . . . 487
15.5.2 Per-Pixel Lighting . . . . . . . . . . . . . . . . . . . . . . . . . 490
15.6 Textures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
15.6.1 Procedural Textures . . . . . . . . . . . . . . . . . . . . . . . . 493
15.6.2 Specular Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
15.6.3 Normal Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
15.7 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 498

16 O PEN GL 4.3, S HADERS AND THE P ROGRAMMABLE P IPELINE : E S -


CAPE V ELOCITY 499
16.1 Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
16.1.1 VAOs and Instanced Rendering Instead of Display Lists . . . . 499
16.1.2 Clipping Planes . . . . . . . . . . . . . . . . . . . . . . . . . . 502
16.1.3 Rest of the Toolbox . . . . . . . . . . . . . . . . . . . . . . . . 503
16.2 Shader Control Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
16.2.1 Shader Subroutines . . . . . . . . . . . . . . . . . . . . . . . . 505
16.2.2 Multiple Program Objects . . . . . . . . . . . . . . . . . . . . 506
16.3 Special Visual Techniques . . . . . . . . . . . . . . . . . . . . . . . . . 508
16.3.1 Blending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
16.3.2 Points and Sprites . . . . . . . . . . . . . . . . . . . . . . . . . 509
16.3.3 Remaining Effects . . . . . . . . . . . . . . . . . . . . . . . . . 511
16.4 More Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
16.4.1 Picking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
16.4.2 Transform Feedback . . . . . . . . . . . . . . . . . . . . . . . . 515
xii 16.5 Tessellation Shaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
16.5.1 TCS (Tessellation Control Shader) . . . . . . . . . . . . . . . . 520 CONTENTS
16.5.2 TES (Tessellation Evaluation Shader) . . . . . . . . . . . . . . 522
16.5.3 TPG (Tessellation Primitive Generator) . . . . . . . . . . . . . 524
16.6 Geometry Shaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
16.6.1 Particle System with Transform Feedback . . . . . . . . . . . . 535
16.7 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 538

IX Anatomy of Curves and Surfaces 539


17 B ÉZIER 541
17.1 Bézier Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
17.1.1 Linear Bézier Curves . . . . . . . . . . . . . . . . . . . . . . . 542
17.1.2 Quadratic Bézier Curves . . . . . . . . . . . . . . . . . . . . . 543
17.1.3 Cubic Bézier Curves . . . . . . . . . . . . . . . . . . . . . . . . 545
17.1.4 General Bézier Curves . . . . . . . . . . . . . . . . . . . . . . . 547
17.2 Bézier Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
17.3 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 556

18 B-S PLINE 557


18.1 Problems with Bézier Primitives: Motivating B-Splines . . . . . . . . . 558
18.2 B-Spline Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
18.2.1 First-Order B-Splines . . . . . . . . . . . . . . . . . . . . . . . 562
18.2.2 Linear B-Splines . . . . . . . . . . . . . . . . . . . . . . . . . . 563
18.2.3 Quadratic B-Splines . . . . . . . . . . . . . . . . . . . . . . . . 566
18.2.4 Cubic B-Splines . . . . . . . . . . . . . . . . . . . . . . . . . . 569
18.2.5 General B-Splines and Non-uniform Knot Vectors . . . . . . . 571
18.3 B-Spline Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
18.4 Drawing B-Spline Curves and Surfaces . . . . . . . . . . . . . . . . . . 584
18.4.1 B-Spline Curves . . . . . . . . . . . . . . . . . . . . . . . . . . 584
18.4.2 B-Spline Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . 585
18.4.3 Lighting and Texturing a B-Spline Surface . . . . . . . . . . . 586
18.4.4 Trimmed B-Spline Surface . . . . . . . . . . . . . . . . . . . . 587
18.5 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 589

19 H ERMITE 591
19.1 Hermite Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
19.2 Natural Cubic Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
19.3 Cardinal Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
19.4 Hermite Surface Patches . . . . . . . . . . . . . . . . . . . . . . . . . . 597
19.5 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 599

X Well Projected 601


20 A PPLICATIONS OF P ROJECTIVE S PACES : P ROJECTION T RANSFOR -
MATIONS AND R ATIONAL C URVES 603
20.1 OpenGL Projection Transformations . . . . . . . . . . . . . . . . . . . 604
20.1.1 Viewing Box to Canonical Viewing Box . . . . . . . . . . . . . 606
20.1.2 Viewing Frustum to Canonical Viewing Box . . . . . . . . . . 607
20.1.3 Projection Matrix in the Pipeline . . . . . . . . . . . . . . . . 610
20.2 Rational Bézier and NURBS Curves and Surfaces . . . . . . . . . . . . 612
20.2.1 Rational Bézier Curves Basics . . . . . . . . . . . . . . . . . . 612
20.2.2 Drawing Rational Bézier Curves . . . . . . . . . . . . . . . . . 615 xiii
CONTENTS 20.2.3 Rational Bézier Curves and Conic Sections . . . . . . . . . . . 616
20.2.4 Properties of Rational Bézier Curves . . . . . . . . . . . . . . 617
20.2.5 Rational Bézier Curves and Projective Invariance . . . . . . . 618
20.2.6 Rational Bézier Curves in the Real World . . . . . . . . . . . . 622
20.2.7 Rational Bézier Surfaces . . . . . . . . . . . . . . . . . . . . . 622
20.2.8 The ‘R’ in NURBS . . . . . . . . . . . . . . . . . . . . . . . . 623
20.3 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 624

XI Time for a Pipe 625


21 P IPELINE O PERATION 627
21.1 Synthetic-Camera Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . 627
21.1.1 Pipeline: Preliminary Version . . . . . . . . . . . . . . . . . . 628
21.1.2 Perspective Division by Zero . . . . . . . . . . . . . . . . . . . 629
21.1.3 Rasterization with Perspectively Correct Interpolation . . . . 632
21.1.4 Revised Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . 636
21.1.5 OpenGL Fixed-function Pipeline . . . . . . . . . . . . . . . . . 637
21.1.6 1D Primitive Example . . . . . . . . . . . . . . . . . . . . . . 638
21.1.7 Exercising the Pipeline . . . . . . . . . . . . . . . . . . . . . . 641
21.2 Ray Tracing Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
21.2.1 Going Global: Shadows . . . . . . . . . . . . . . . . . . . . . . 643
21.2.2 Going Even More Global: Recursive Reflection and Transmission 645
21.2.3 Implementing Ray Tracing . . . . . . . . . . . . . . . . . . . . 648
21.3 Radiosity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
21.3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
21.3.2 Basic Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650
21.3.3 Computing Form Factors . . . . . . . . . . . . . . . . . . . . . 652
21.3.4 Solving the Radiosity Equation to Determine Patch Brightnesses 654
21.3.5 Implementing Radiosity . . . . . . . . . . . . . . . . . . . . . . 655
21.4 Summary, Notes and More Reading . . . . . . . . . . . . . . . . . . . . 656

Appendices 657
A P ROJECTIVE S PACES AND T RANSFORMATIONS 657
A.1 Motivation and Definition of the Projective Plane . . . . . . . . . . . . 658
A.2 Geometry on the Projective Plane and Point-Line Duality . . . . . . . 660
A.3 Homogeneous Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . 660
A.4 Structure of the Projective Plane . . . . . . . . . . . . . . . . . . . . . 662
A.4.1 Embedding the Real Plane in the Projective Plane . . . . . . . 662
A.4.2 A Thought Experiment . . . . . . . . . . . . . . . . . . . . . . 662
A.4.3 Regular Points and Points at Infinity . . . . . . . . . . . . . . 663
A.5 Snapshot Transformations . . . . . . . . . . . . . . . . . . . . . . . . . 665
A.6 Homogeneous Polynomial Equations . . . . . . . . . . . . . . . . . . . 669
A.6.1 More About Point-Line Duality . . . . . . . . . . . . . . . . . 670
A.6.2 Lifting an Algebraic Curve from the Real to the Projective Plane 671
A.6.3 Snapshot Transformations Algebraically . . . . . . . . . . . . . 674
A.7 The Dimension of the Projective Plane and Its Generalization to Higher
Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674
A.8 Projective Transformations Defined . . . . . . . . . . . . . . . . . . . . 675
A.9 Projective Transformations Geometrically . . . . . . . . . . . . . . . . 676
A.10 Relating Projective, Snapshot and Affine Transformations . . . . . . . 681
xiv A.10.1 Snapshot Transformations via Projective Transformations . . . 682
A.10.2 Affine Transformations via Projective Transformations . . . . 683 CONTENTS
A.11 Designer Projective Transformations . . . . . . . . . . . . . . . . . . . 685

B M ATH S ELF -T EST 691


C M ATH S ELF -T EST S OLUTIONS 697
B IBLIOGRAPHY 705
S UBJECT I NDEX 713
P ROGRAM I NDEX 730

xv
Preface

W
elcome to the third edition of Computer Graphics Through OpenGL:
From Theory to Experiments! The first edition appeared late 2010 and
the second four years after in 2014. Now, it’s been another four years in
which I received a lot of thoughtful and, happily, mostly positive feedback. I heard
from instructors, students, as well as individuals using the book for self-study. Their
observations together with my own classroom experience started me off a year ago
writing a new edition. It’s been a fairly intense past several months, most of my
waking hours spent sitting where I am now in front of the computer. But it’s been
fun too – being in communion with an imaginary reader who I am trying to enlighten
and keep engaged at the same time – and I am pleased with the result. I hope you
will be too. Let’s get to the facts.

About the Book


This is an introductory textbook on computer graphics with equal emphasis on theory
and practice. The programming language used is C++, with OpenGL as the graphics
API, which means calls are made to the OpenGL library from C++ programs. OpenGL
is taught from scratch.
The book has been written to be used as a textbook for a first college course, as
well as for self-study.
After Chapters 1-16 – the undergraduate core of the book – the reader will have a
good grasp of the concepts underpinning 3D computer graphics, as well as an ability
to code sophisticated 3D scenes and animation, including games and movies. We
begin with classical pre-shader OpenGL before proceeding to the latest OpenGL 4.x
(more about our exposition style further on). Chapters 17-21, though advanced, but
still mainstream, could be selected topics for an undergraduate course or part of a
second course.

Specs
This book comprises 21 chapters, an extended appendix on a fundamental math topic,
plus two more appendices containing a math self-test and its solutions. It comes with
approximately 180 programs, 270 experiments based on these programs, 750 exercises,
including theory and programming exercises, 110 worked examples, and 700 four-color
illustrations, include drawings and screenshots. An instructor’s manual containing
solutions to selected exercises is available from the publisher. The book was typeset
using LATEX and figures drawn in Adobe Illustrator.

From the Second Edition to the Third


• Cover to cover revision and reorganization of topics.
New topics include: xvii
Preface • Timer queries and performance measurement.
• Importing externally created objects.
• Texturing spheres.
• Framebuffer objects.
• Rendering to texture.
• Texture matrices.
• Cube mapping a skybox.
• Shadow mapping curved surfaces.
• OpenGL 4.x:
◦ Procedural textures.
◦ Specular maps.
◦ Normal maps.
◦ Multiple program objects.
◦ Particle systems with transform feedback.

• 10 new programs, 20 new experiments, 100 new exercises, 10 new examples, 50


new figures.
• Programming environment simplified, programs developed on Windows 10 and
Microsoft Visual Studio (MSVS) 2015 and tested on MSVS 2017.

Target Audience

• Students in a first university CG course, typically offered by a CS department


at a junior/senior level. This is the primary audience for which the book was
written.
• Students in a second or advanced CG course, who may use the book as
preparation or reference, depending on the goals. For example, the book would
be a useful reference for a study of 3D design – particularly, Bézier, B-spline
and NURBS theory – and of projective transformations and their applications
in CG.
• Students in a non-traditional setting, e.g., studying alone or in a professional
course or an on-line program. The author has tried to be especially considerate
of the reader on her own.
• Professional programmers, to use the book as a reference.

Prerequisites

Zero knowledge of computer graphics is presumed. However, the student is expected


to know the following:

• Basic C++ programming. There is no need to be an expert programmer. The


C++ program serves mainly as an environment for the OpenGL calls, so there’s
rarely need for fancy footwork in the C++ part itself.
• Basic math. This includes coordinate geometry, trigonometry and linear algebra,
all at college first-course level (or, even strong high school in some cases). For
intended readers of the book who may be unsure of their math preparation, we
have a self-test in Appendix B, with solutions in Appendix C. The test should
xviii tell exactly how ready you are and where the weaknesses are.
Resources Preface
The following are available through the book’s website www.sumantaguha.com:

• Sample chapters, table of contents, preface, subject and program index, math
self-test and solutions at the Home page.
• Program source code, developed on a Windows 10 platform using the Microsoft
Visual Studio Community 2015 IDE and subsequently tested to run with MSVS
Community 2017, which should run on other versions of Windows/MSVS, as
well as Mac OS and Linux platforms. The programs are arranged chapter-wise
in the top-level folder ExperimenterSource at the Downloads page.
• Guide to installing OpenGL and running the programs on a Windows/MSVS
platform at the Downloads page.
• Multiplatform Experimenter software to run the experiments at the Downloads
page. Experimenter’s interface is Experimenter.pdf, a file containing all the
experiments from the book; except for those in Chapter 1, each is clickable
to bring up the related program and workspace. Experimenter is only an aid
and not mandatory – each program is stand-alone. However, it is the most
convenient way to run experiments in their book order.
• Book figures in jpg format arranged in sequence as one PowerPoint presentation
per chapter at the Instructor page.
• Instructor’s manual with solutions to 100 problems – instructors who have
adopted the textbook can submit a request at the Instructor page.

Pedagogical Approach
Code and theory have been intertwined as far as possible in what may be called a
theory-experiment-repeat loop: often, following a theoretical discussion, the reader is
asked to perform validating experiments (run code, that is); sometimes, too, the other
way around, an experiment is followed by an explanation of what is observed. It’s
kind of like discovering physics.
Why use an API?
Needless to say, I am not a fan of the API-agnostic approach to teaching CG, where
focus is on principles only, with no programming practice.
Undergrads, typically, love to code and make things happen, so there is little
justification to denying the new student the joy of creating scenes, movies and games,
not to mention the pride of achievement. And, why not leverage the way code and
theory reinforce one another when teaching the subject, or learning on one’s own,
when one can? Would you want Physics 101 without a lab section?
Moreover, OpenGL is very well-designed and the learning curve short enough to
fully integrate into a first CG course. And, it is supported on every OS platform with
drivers for almost every graphics card on the market; so, in fact, OpenGL is there to
use for anyone who cares to.
Note to student: Our pedagogical style means that for most parts of the book you
want a computer handy to run experiments. So, if you are going to snuggle up with it
at night, make it a threesome with a notebook.
Note to instructor : Lectures on most topics – both of the theory and programming
practice – are best based around the book’s experiments, as well as those you develop
yourself. The Experimenter resource makes this convenient. Slides other than the
plentiful book figures, the latter all available on-line, are rarely necessary.
How to teach modern shader-based OpenGL?
Our point of view needs careful explanation as it is different from some of our peers’.
Firstly, to push the physics analogy one more time, even though relativistic mechanics
seems to rule the universe, in the classroom one might prefer doing classical physics
before relativity theory. xix
Preface Shaders, which are the programmable parts of the modern OpenGL pipeline, add
great flexibility and power. But, so too, do they add a fair bit of complexity – even
a cursory comparison of our very first program square.cpp from Chapter 2 with
its equivalent in fourth-generation OpenGL, squareShaderized.cpp, complemented
with a vertex and a fragment shader in Chapter 15, should convince the reader of this.
Consider more carefully, say, a vertex shader. It must compute the position
coordinates of a vertex, taking into account all transformations, both modelview and
projection. However, in the classical fixed-function pipeline the user can simply issue
commands such as glTranslatef(), glFrustum(), etc., leaving to OpenGL actual
computation of the transformed coordinates; not so for the programmable pipeline,
where the reader must write herself all the needed matrix operations in the vertex
shader. We firmly believe that the new student is best served learning first how to
transform objects according to an understanding of simply how a scene comes together
physically (e.g., a ball falls to the ground, a robot arm bends at the elbow, etc.) with
the help of ready-to-use commands like glTranslatef(), and, only later, how to
define these transforms mathematically.
Such consideration applies as well to other automatic services of the fixed-function
pipeline which allow the student to focus on phenomena, disregarding initially
implementation. For example, as an instructor, I would much prefer to teach first how
diffuse light lends three-dimensionality, specular light highlights, and so on, gently
motivating Phong’s lighting equation, leaving OpenGL to grapple with its actual
implementation, which is exactly what we do in Chapter 11.
In fact, we find an understanding of the fixed-function pipeline makes the subsequent
learning of the programmable one significantly easier because it’s then clear exactly
what the shaders should try to accomplish. For example, following the fixed-function
groundwork in Chapter 11, writing shaders to implement Phong lighting, as we do in
Chapter 15, is near trivial.
We take a similarly laissez-faire attitude to classical OpenGL syntax. So long as it
eases the learning curve we’ll put up with it. Take for example the following snippet
from our very first program square.cpp:

glBegin(GL_POLYGON);
glVertex3f(20.0, 20.0, 0.0);
glVertex3f(80.0, 20.0, 0.0);
glVertex3f(80.0, 80.0, 0.0);
glVertex3f(20.0, 80.0, 0.0);
glEnd();

Does it not scream square – even though it’s immediate mode and uses the discarded
polygon primitive? So, we prefer this for our first lesson, avoiding thereby the
distraction of a vertex array and the call glDrawArrays(GL TRIANGLE STRIP, 0, 4),
as in the equivalent 4.x program squareShaderized.cpp, our goal being a simple
introduction of the synthetic-camera model.
With these thoughts in mind the book starts in Chapter 2 with classical pre-shader
OpenGL, progressing gradually deeper into the API, developing CG ideas in parallel,
in a so-called theory-experiment-repeat loop. So, what exactly is an experiment?
An experiment consists either of running a book program – each usually simple for
the purpose of elucidating a single idea – or attempting to modify one based on an
understanding of the theory in order, typically, to achieve a particular visual result.
By the end of Chapter 14 the student will have acquired proficiency in pre-shader
OpenGL, a perfectly good API in itself. As well, equally importantly, she will have
an understanding of CG principles and those underlying the OpenGL pipeline, which
will dramatically ease her way through the concepts and syntax of OpenGL 4.x, the
newest generation of the API, covered in Chapters 15-16.
Does this kind of introduction to modern OpenGL, via the old and, possibly,
obsolete, not ingrain bad habits? Not at all, from our experience. When push comes
xx to shove, how hard is it to replace polygons with triangle strips? Or, use vertex buffer
objects (VBOs) and vertex array objects (VAOs) to store data? Does our approach Preface
cost timewise? If the goal is OpenGL 4.x, then, yes, it does take somewhat longer,
but there are various possible learning sequences through the book and 4.x certainly
can be reached and covered in a semester.
In short, then, we believe the correct way to modern OpenGL is through the
classical version of the API because this allows the learning process to begin at
a high level, so that the student can concentrate on gaining an overall end-to-end
understanding of the CG pipeline first, leaving the OpenGL system to manage low-level
processes (i.e., those inside the pipeline like setting transformation and projection
matrices, defining fragment colors, and such). Once she has a high-level mastery,
subsequently “descending” into the pipeline to take charge of fixed-function parts in
order to program them instead will, in fact, be far less arduous than if she tried to do
both – learn the basics and program the pipeline – at the same time.
Another point to note in this context is that, as noted before, classical OpenGL is
a complete API in itself which, in fact, can be more convenient for certain applications
(e.g., it allows one access to the readymade GLUT objects like spheres and toruses).
There are, as well, thousands of currently live applications written in classical OpenGL,
which are not going go to be discarded or rewritten any time soon – the reason, in fact,
for the Khronos Group to retain the compatibility version of the API – so familiarity
with older syntax can be useful for the intending professional.
What about Vulkan?
We thought you might ask. Vulkan is the much-hyped “successor” to OpenGL. It is a
highly explicit API, taking the programmer close to the hardware and asking her to
specify almost all facets of the pipeline from end to end. Benefits of programming
near the hardware include thin drivers, reduced run-time overhead and the ability to
expose parallelism in the GPU. (Vulkan is not only a 3D graphics API, but used to
program GPU-heavy compute applications as well.)
However, Vulkan’s explicitness and consequent verbosity make it highly unsuitable
as an introductory CG API. Here are some program sizes to begin with. The first
OpenGL program in the book, square.cpp, which draws a black square on a white
background, is about 90 lines of code in pre-shader 2nd generation OpenGL; a
functionally equivalent program, squareShaderized.cpp, written in OpenGL 4.3
later on in the book is 190 lines plus 25 lines of shader code; a minimal equivalent
Vulkan program, squareVulkanized.cpp, written separately by the author is 1,100
lines (no, that’s no misprint – the reader will find the program at the Downloads page
of the book’s website) plus 30 lines of shader code. Figure 1 is a screenshot.
Moreover, explicitness requires a Vulkan programmer to be familiar with the
Figure 1: Screenshot of
functioning of the graphics pipeline at a low level in order to specify it, which almost squareVulkanized.cpp, a
instantly disqualifies it from being a beginner’s API. Further, delaying programming 1000+ line Vulkan
until after the pipeline has been covered goes utterly against our own pedagogical program.
approach which is to engage students with code the first day.
So, is OpenGL, or for that matter, this book, of any use for someone intending to
learn Vulkan? Well:
(a) The Vulkan graphics pipeline is essentially the same as OpenGL’s. Therefore,
learning OpenGL is progress toward Vulkan. Moreover, once a programmer has
mastered OpenGL, she has most of what’s needed to “take full charge” of the
pipeline, which is what Vulkan is all about.
(b) The runtime gains of Vulkan don’t begin to show up in any significant way
until one gets to complex scenes with lots of textures, objects and animation.
Less complicated applications - including, obviously, those in any introductory
CG book - benefit little performance-wise from being written (or, rewritten) in
Vulkan, not justifying the huge overhead in code.
This means that many OpenGL apps are going to stay that way and new ones
continue to be written. It’s a matter of knowing which tool to use: pre-shader xxi
Preface OpenGL, OpenGL 4.x, Vulkan, . . .. (Hooking up a U-Haul trailer to the back of
a Ferrari is never a good idea.)

Nevertheless, if you are of the Vulkan or bust frame of mind then the advice we would
have is to study this book up to Chapter 16, when you will have a solid understanding
of fourth-generation OpenGL, then pick up, say, the canonical Vulkan guide [131],
through which you should then be able to make quick progress.

Capsule Chapter Descriptions


Part I: Hello World
Chapter 1: An Invitation to Computer Graphics
A non-technical introduction to the field of computer graphics.
Chapter 2: On to OpenGL and 3D Computer Graphics
Begins the technical part of the book. It introduces OpenGL and fundamental
principles of 3D CG.

Part II: Tricks of the Trade


Chapter 3: An OpenGL Toolbox
Describes a collection of OpenGL programming devices, including vertex arrays, vertex
buffer and array objects, mouse and key interaction, pop-up menus, and several more.

Part III: Movers and Shapers


Chapter 4: Transformation, Animation and Viewing
Introduces the theory and programming of animation and the virtual camera. Explains
user interactivity via object selection. Foundational chapter for game and movie
programming.
Chapter 5: Inside Animation: The Theory of Transformations
Presents the mathematical theory behind animation, particularly linear and affine
transformations in 3D.
Chapter 6: Advanced Animation Techniques
Describes frustum culling, occlusion culling as well as orienting animation using both
Euler angles and quaternions, techniques essential to programming games and busy
scenes.

Part IV: Geometry for the Home Office


Chapter 7: Convexity and Interpolation
Explains the theory of convexity and the role it plays in interpolation, which is the
procedure of spreading material properties from the vertices of a primitive to its
interior.
Chapter 8: Triangulation
Describes how and why complex objects should be split into triangles for efficient
rendering.
Chapter 9: Orientation
Describes how the orientation of a primitive is used to determine the side of it that
the camera sees, and the importance of consistently orienting a collection of primitives
making up a single object.

Part V: Making Things Up


xxii Chapter 10: Modeling in 3D Space
Systematizes the principles of modeling both curves and surfaces, including Bézier and Preface
fractal. Shows how to import objects from external design environments. Foundational
chapter for object design.

Part VI: Lights, Camera, Equation


Chapter 11: Color and Light
Explains the theory of light and material color, the interaction between the two, and
describes how to program light and color in 3D scenes. Foundational chapter for scene
design.
Chapter 12: Textures
Explains the theory of texturing and how to apply textures to objects and render to a
texture.
Chapter 13: Special Visual Techniques
Describes a set of special techniques to enhance the visual quality of a scene,
including, among others, blending, billboarding, stencil buffer methods, image and
pixel manipulation, cube mapping a skybox, and shadow mapping.

Part VII: Pixels, Pixels, Everywhere


Chapter 14: Raster Algorithms
Describes low-level rendering algorithms to determine the set of pixels on the screen
corresponding to a line or a polygon.

Part VIII: Programming Pipe Dreams


Chapter 15: OpenGL 4.3, Shaders and the Programmable Pipeline: Liftoff
Introduces 4th generation OpenGL and GLSL (OpenGL Shading Language) and how
to vertex and fragments shaders to program the pipeline, particularly to animate,
light and apply textures.
Chapter 16: OpenGL 4.3, Shaders and the Programmable Pipeline: Escape Velocity
Continuing onto advanced 4th generation OpenGL topics, including, among others,
instanced rendering, shader subroutines, transform feedback, particle systems, as well
as tessellation and geometry shaders.

Part IX: Anatomy of Curves and Surfaces


Chapter 17: Bézier
Describes the theory and programming of Bézier primitives, including curves and
surfaces.
Chapter 18: B-Spline
Describes the theory and programming of (polynomial) B-spline primitives, including
curves and surfaces.
Chapter 19: Hermite
Introduces the basics of Hermite curves and surfaces.

Part X: Well Projected


Chapter 20: Applications of Projective Spaces: Projection Transformations and
Rational Curves
Applies the theory of projective spaces to deduce the projection transformation in
the graphics pipeline. Introduces rational Bézier and B-spline, particularly NURBS,
theory and practice.

Part XI: Time for a Pipe


Chapter 21: Pipeline Operation xxiii
Preface Gives a detailed view of the synthetic-camera and ray-tracing pipelines and introduces
radiosity.

Appendix A: Projective Spaces and Transformations


A CG-oriented introduction to the mathematics of projective spaces and transforma-
tions. Provides a complete theoretical background for Chapter 20 on applications of
projective spaces.

Appendix B: Math Self-Test


A self-test to assess math readiness for intending readers.

Appendix C: Math Self-Test Solutions


Solutions for the math self-test.

Chapter 1 Chapter 2
An Invitation On to OpenGL
to Computer and 3D Computer
Graphics Graphics

Chapter 3 Chapter 4 Chapter 7 Chapter 14


An OpenGL Transformation, Convexity and Raster
Toolbox Animation and Interpolation Algorithms
Viewing

Chapter 5 Chapter 6 Chapter 8


Inside Animation: Advanced
The Theory of Animation Triangulation
Transformations Techniques

Chapter 9

Orientation

Chapter 10
Modeling in
3D Space

Chapter 11 Chapter 17 Appendix A


Projective
Color and Light Bézier Spaces and
Transformations

Chapter 12 Chapter 18 Chapter 21


Texture B-Spline Pipeline
Operation

Chapter 13 Chapter 19 Chapter 20


Special Visual Applications of
Hermite Projective
Techniques Spaces: ...

Chapter 15
OpenGL 4.3,
Shaders ... :
Liftoff

Chapter 16
OpenGL 4.3,
Shaders ... :
Escape Velocity

Figure 2: Chapter dependence chart: dashed arrows represent weak dependencies.

xxiv
Suggested Course Outlines Preface
See the chapter dependencies in Figure 2.
(1) Undergraduate one-semester first CG course:
This course should be based on Chapters 1-16, though full coverage might be
ambitious for one semester. Instructors may pick topics to emphasize or skip,
depending on their goals for the course and the chapter dependence chart.
For example, for more practice and less theory, a possible sequence would be 1 →
2 → 3 → 4 → 6 (only frustum culling) → 7 → 8 → 9 → 10 (skip curve/surface
theory) → 11 → 12 → 13 → 15 → 16.
Even this abbreviated sequence may be hard to pack into one semester. Please
keep in mind that when choosing what to write about the author preferred to
err on the side of excess rather than less. So, almost always will the instructor
find more material in a chapter than she cares to teach – we leave her to pick
her way out.
The most effective teaching method with this book is to base discussion around
experiments – both from the book and those the instructor develops herself.
Our Experimenter software makes this especially convenient. Students should be
involved in the experiments, running code simultaneously on their own machines
in class. Use of slides should be minimized except, possibly, for the plentiful
book figures, which are available to download, arranged as one PowerPoint
presentation per chapter.
(2) Advanced CG courses:
This book could serve as a reference for a study of 3D design – particularly,
Bézier (Chapter 17), B-spline (Chapter 18) and rational Bézier and NURBS
theory (Chapter 20) – and of projective transformations and their applications
(Appendix A and Chapter 20). From a practical point of view, Chapters 15-16
go fairly deep into the fourth generation of OpenGL and the GLSL, useful for
students who may be familiar with only the classical pipeline.
(3) Self-study:
A recommended first pass would be 1 → 2 → 3 → 4 → 7 → 8 → 9 (go light on
7-9 if your math is rusty) → 10 (skip theory) → 11 → 12 → 13 → 15 → 16.
Following this the student should take up a fair-sized programming project,
returning to the book as needed. For the theoretically-inclined there’s a lot to
keep her busy in Chapters 5 and 17-21.

Acknowledgments
I owe a lot to many people, most of all students whom I have had the privilege of
teaching in my CG classes over the years at UW-Milwaukee and then the Asian
Institute of Technology.
I thank KV, Ichiro Suzuki, Glenn Wardius, Mahesh Kumar, Le Phu Binh, Maria
Sell and, especially, Paul McNally, for their support at UWM, where I began to teach
CG and learn OpenGL.
I am grateful to my colleagues and the staff and students at AIT for such a pleasant
environment, which allowed me to combine teaching and research commitments with
the writing of a book.
Particular thanks at AIT to Vu Dinh Van, Nguyen Duc Cong Song, Ahmed
Waliullah Kazi, Hameedullah Kazi, Long Hoang, Songphon Klabwong, Robin Chanda,
Sutipong Kiatpanichgij, Samitha Kumara, Somchok Sakjiraphong, Pyae Phyo Myint
Soe, Adbulrahman Otman, Sushanta Paudyal, Akila de Silva, Nitchanun Saksinchai,
Thee Thet Zun, Suwanna Xanthavanij, Visutr Boonnateephisit, Matt Dailey, and our
ever-helpful secretaries K. Siriporn and K. Tong. xxv
Preface I am grateful to Kumpee Teeravech, Kanit Tangkathach, Thanapoom Veeranitinun,
Pongpon Nilaphruek, and Wuttinan Sereethavekul, students of my CG course at AIT,
for allowing me to use programs they wrote.
I owe an enormous debt of gratitude to my former student Chansophea Chuon for
hundreds of hours of help with the first edition, which got this book off the ground in
the first place. I thank Somying Pongpimol for her brilliant Illustrator drawings. She
drew several of the figures based on my rather amateurish original Xfig sketches. I
would like to thank Olivier Nicole for help with the book’s website.
I am especially grateful to Brian Barsky for encouraging me to persevere after
seeing an early and awkward draft of the first edition, and subsequently inviting the
finished product to the series he was then editing. Relatedly, I thank my neighbor
Doug Cooper two floors down for putting me in touch with Brian at the time Brian
was scouting prospective authors.
I want to acknowledge the production team at Taylor & Francis who went out of
their way for this book. Particularly, I want to thank my editor Randi Cohen who is
as professional and efficient as she is pleasant to deal with.
I am grateful to readers of the first and second editions, as well as reviewers
who looked over drafts and proposals, whose comments led, hopefully, to significant
improvements.
I have nothing but praise for the DJs and kindly staff of the Mixx nightclub in
downtown Bangkok whose dance floor provided a much-needed sanctuary for me to
blow off steam after long hours on the computer.
I acknowledge the many persons and businesses who were kind enough to allow
me to include images to which they own copyrights.
On a personal note, I express my deep gratitude to Dr. Anupam De for keeping
Kamaladi healthy enough that I could concentrate on the first edition through the
few years that I spent writing it.
Finally, I must say that had I not had the opportunity to study computer science
in the United States and teach there, I would never have reached a position where I
could even contemplate writing a textbook. It’s true, too, that had I not moved to
Thailand, this book would never have begun to be written. This is an enchanting
country with a strangely liberating and lightening effect – to which thousands of
expats can attest – that encourages one to express oneself.

Website and Contact Information


The book’s website is at www.sumantaguha.com. Users of the book will find there
various resources including downloads. The author welcomes feedback, corrections
and suggestions for improvement emailed to him at sg@sumantaguha.com.

xxvi
About the Author

Sumanta Guha earned a Ph.D. in mathematics from the Indian Statistical Institute,
Kolkata, in 1987. From 1984 to 1987 he taught mathematics at Jadavpur University
in Kolkata. He left in 1987 to study computer science at the University of Michigan
in Ann Arbor, where he earned a Ph.D. in 1991. On graduating from Michigan he
joined the Electrical Engineering and Computer Science faculty of the University of
Wisconsin-Milwaukee where he taught from 1991 to 2002. In 2002 he moved to the
Computer Science and Information Management program of the Asian Institute of
Technology in Thailand, where he is currently an adjunct professor. His research
interests include computational geometry, computer graphics, computational topology,
robotics and data mining.

xxvii
Another random document with
no related content on Scribd:
arrangement of its parts, reminding one somewhat of the compound eyes
of the higher Insects. This structure is represented in Fig. 100, B, C; it is
said by Sir John Lubbock to be present in some of the Lipuridae that have
no ocelli, and he therefore prefers to speak of it as the "post-antennal"
organ.

A very characteristic feature in the Collembola is the slight development


of the tracheal system. Although writers are far from being in accord as to
details, it seems that stigmata and tracheae are usually absent. In
Smynthurus there are, however, according to Lubbock,—whose
statement is confirmed by Meinert and Tullberg,—a pair of stigmata
situate on the head below the antennae, and from these there extends a
tracheal system throughout the body. Such a position for stigmata is
almost, if not quite unique in Insects; Grassi, however, seems to have
found something of the kind existing in the embryo of the bee.

At present only a small number of species of the Order Aptera are known;
Lubbock recognised about sixty British species, and Finot sixty-five as
found in France. The North American forms have not received so much
attention as the European, and the Aptera of other countries, though they
are probably everywhere fairly numerous, are scarcely known at all. A few
have been described from the Indo-Malayan region and some from Chili,
and the writer has seen species from the West Indian and Sandwich
Islands. All the exotic forms as yet detected are very similar to those of
Europe.

The Thysanura are probably not very numerous in species, and appear to
be in general intolerant of cold. With the Collembola the reverse is the
case. They are excessively numerous in individuals; they are found nearly
everywhere on the surface of the ground in climatic conditions like those
of our country, while no less than sixteen species have been found in
Nova Zembla and one each in Kerguelen and South Georgia. One
species, if not more, of Podura, lives on the surface of stagnant waters,
on which the minute creatures may frequently be seen leaping about in
great numbers after being disturbed.

In 1874 the plain of Gennevilliers in France was copiously irrigated; in the


following year the soil was still very damp, and there existed numerous
pools of stagnant water, on the surface of which Podura aquatica was
developed in such prodigious quantity as to excite the astonishment of
the inhabitants of the region.

Accounts have been frequently given of the occurrence on snow and


glaciers of Insects spoken of as snow-fleas, or snow-worms. These
mostly relate to Poduridae, which are sometimes found in countless
number in such situations. The reason for this is not well understood.
According to F. Löw,[123] on the 17th of March at St. Jacob in Carinthia,
Parson Kaiser observed, on the occurrence of the first thaw-weather,
enormous numbers of a Podura (? Achorutes murorum) on the surface of
the snow for an extent of about half a mile, the snow being rendered
black in appearance by them; eleven days afterwards they were found in
diminished numbers on the snow, but in large quantity on the water left by
its melting. This account suggests that the occurrence of the Insects on
the snow was merely an incident during their passage from the land,
where they had been hibernating, to the surface of the water.

One little member of the Lipuridae, Anurida maritima (Lipura maritima of


Lubbock), has the habit, very unusual for an Insect, of frequenting salt
water. It lives amongst the rocks on the shores of the English Channel,
between high and low tide-marks. Its habits have been to some extent
observed by Laboulbène[124] and Moniez[125]; it appears to be
gregarious, and when the tide is high, to shelter itself against the
commotions of the water in chinks of the rocks and other positions of
advantage. When the tide is out the Insects apparently delight to
congregate in masses on the surface of the rock pools. This Anurida can
endure prolonged immersion; but both the observers we are quoting say
that it is, when submerged, usually completely covered with a coat of air
so that the water does not touch it. The little creature can, however, it
would appear, subsist for some time in the pools of salt water, even when
it is not surrounded by its customary protecting envelope of the more
congenial element. Its food is said, on very slender evidence, to consist of
the remains of small marine animals, such as Molluscs. We reproduce
some of Laboulbène's figures (Fig. 100); the under-surface shows at a the
divided papilla of the ventral tube; B, C represent the peculiar
prostemmatic organ, alluded to on p. 193, in its mature and immature
states.
Fig. 100.—Anurida maritima: A, under-surface; a, papilla of ventral tube; B,
prostemmatic organ of young; C, of adult. (After Laboulbène.)

Very little information exists as to the life-history of the Aptera; as for their
food, it is generally considered to consist of refuse vegetable or animal
matter. It is usual to say that they are completely destitute of
metamorphosis, but Templeton says of Lepisma niveo-fasciata that "the
young differ so much from the mature Insect that I took them at first for a
distinct species; the thoracic plates are proportionately less broad, and
the first is devoid of the white marginal band." As regards the moults, it
would appear that in this, as in so many other points, great diversity
prevails, Grassi stating that in Campodea there is a single fragmentary
casting of the skin; and Sommer informing us that in Macrotoma plumbea
the moults are not only numerous, but continue, after the creature has
attained its full growth, throughout life.

A very marked feature of the Aptera is their intolerance of a dry


atmosphere. Although Campodea can exist under very diverse
conditions, it dies very soon after being placed in a dry closed tube; and
the same susceptibility appears to be shared by all the other members of
the Order, though it is not so extreme in all; possibly it may be due to
some peculiarity in the structure of the integument. So far as tolerance of
heat and cold goes, the Aptera can apparently exist in any climate, for
though some of the species extend to the Arctic regions, others are
peculiar to the tropics.

Thysanura are recorded by Klebs and Scudder as occurring commonly in


amber; the latter author has described a fossil, supposed to be a
Lepisma, found in the Tertiary deposits at Florissant. Scudder has also
described another fossil, likewise from Florissant, which he considers to
form a special sub-order of Thysanura—Ballostoma—but it is extremely
doubtful whether this anomalous creature should be assigned to the
Order at all. A still older fossil, Dasyleptus lucasii Brongniart, from the
Carboniferous strata in France, is considered to belong to the Order
Aptera, but it must be admitted there is some doubt on this point.

The interest aroused in the minds of naturalists by the comparatively


simple forms of these purely wingless and therefore anomalous Insects
has been accompanied by much discussion as to their relations to other
Insects, and as to whether they are really primitive forms, or whether they
may perhaps be degenerate descendants from some less unusual states
of Insect-life. Mayer and Brauer dissociated our Aptera entirely from other
Insects, and proposed to consider the Hexapoda as being composed of
two groups—(1) the Apterygogenea, consisting of the few species we
have been specially considering; and (2) the Pterygogenea, including all
the rest of the immense crowd of Insect forms. They were not, however,
able to accompany their proposed division by any satisfactory characters
of distinction, and the subsequent progress of knowledge has not
supported their view, all the best investigators having found it necessary
to recognise the extremely intimate relations of these Insects with the
Orthoptera. Meinert thought that Lepisma must be included in the
Orthoptera; Grassi proposes to consider the Thysanura as a distinct
division of Orthoptera; and Oudemans recognises the close relations
existing between Machilis and Orthoptera proper. Finot includes the
Aptera in his Orthoptères de la France, and a species of Japyx has
actually been described by a competent entomologist as an apterous
earwig. At present, therefore, we must conclude that no good distinction
has been found to justify the separation of the Aptera from all other
Insects.

The taxonomy of the Collembola has not yet been adequately treated,
and it is possible that more grounds will be found for separating them as a
distinct Order from the Thysanura,—a course that was advocated by
Lubbock,—than exist for dividing these latter from the Orthoptera proper.
There are apparently no grounds for considering the Aptera to be
degenerate Insects, and we may adopt the view of Grassi, that they are
primitive, or rather little evolved forms. It must be admitted that there are
not at present any sufficient reasons for considering these Insects to be
"ancient" or "ancestral." The vague general resemblance of Campodea to
many young Insects of very different kinds is clearly the correlative of its
simple form, and is no more proof of actual ancestry to them than their
resemblances inter se are proofs of ancestry to one another. But even if
deprived of its claim to antiquity and to ancestral honours, it must be
admitted that Campodea is an interesting creature. In its structure one of
the most fragile of organisms, with a very feeble respiratory system,
inadequate organs of sense, only one pair of ovarian tubes, very
imperfect mouth-organs, and a simple alimentary canal, it nevertheless
flourishes while highly-endowed Insects become extinct. In the suburban
gardens of London, on the shores of the Mediterranean, on the summits
of the higher Pyrenees, in North America even it is said in the caves of
Kentucky, and in India, Campodea is at home, and will probably always
be with us.

CHAPTER VIII

ORTHOPTERA—FORFICULIDAE, EARWIGS—HEMIMERIDAE

Order II.—Orthoptera.

Insects with the mouth parts conspicuous, formed for biting, the four palpi very distinct,
the lower lip longitudinally divided in the middle. The tegmina (mesothoracic wings), of
parchment-like consistence, in repose closed on the back of the Insect so as to protect it.
The metathoracic wings, of more delicate consistence, ample, furnished with radiating or
divergent nervures starting from the point of articulation, and with short cross nervules
forming a sort of network; in repose collapsing like a fan, and more or less completely
covered by the tegmina (except in certain Phasmidae, where, though the wings are
ample, the tegmina are minute, so that the wings are uncovered). In a few forms (winged
Forficulidae and some Blattidae) the metathoracic wings are, in addition to the
longitudinal folding, contracted by means of one or two transverse folds. The mode of
growth of each individual is a gradual increase of size, without any abrupt change of
form, except that the wings are only fully developed in the final condition. There is no
special pupal instar. Species in which the wings are absent or rudimentary are
numerous.

The Orthoptera are Insects of comparatively large size. The Order,


indeed, includes the largest of existing Insects, while none are so minute
as many of the members of the other Orders are; three millimetres is the
least length known for an Orthopterous Insect, and there are very few so
small, though this is ten times the length of the smallest beetle. The Order
includes earwigs, cockroaches, soothsayers or praying-insects, stick- and
leaf-insects, grasshoppers, locusts, green grasshoppers, and crickets.

The changes of form that accompany the growth of the individual are
much less abrupt and conspicuous than they are in most other Insects.
The metamorphosis is therefore called Paurometabolous. It has been
supposed by some naturalists that Orthoptera go through a larger portion
of their development in the egg than other Insects do. This does not
clearly appear to be the case, though it seems that there are distinctions
of a general character in the embryology; the period of development in
the egg is prolonged, and the yolk is said by Wheeler[126] to be more than
usually abundant in comparison with the size of the young embryo. The
embryonic development may in tropical countries be accomplished in
three weeks (see Mantidae), but in countries where winter supervenes,
the period may in some species be extended over seven or eight months.

The external features of the post-embryonic development—a term that is


more convenient in connexion with Orthoptera than metamorphosis—are
as follows: the wings are never present when the Insect is first hatched,
but appear subsequently, and increase in size at the moults; the form and
proportions of the segments of the body—especially of the thorax—
undergo much change; an alteration of colour occurs at some of the
moults, and the integument becomes harder in the adult condition.
Neither the development of the internal organs, nor the physiological
processes by which the changes of external form are effected, appear to
have been studied to any great extent.

Many of the Orthoptera do not possess wings fit for flight, and some
species even in the adult state have no trace whatever of such organs.
Flight, indeed, appears to be of minor importance in the Order; in many
cases where the wings exist they are purely musical organs, and are not
of any use for flight. The apterous and the flightless conditions are not
confined to one division of the Order, but are found in all the families and
in many of their subdivisions. As the front pair of wings in Orthoptera do
not really carry out the function of flight, and as they differ in several
particulars from the hinder pair, or true wings, it is usual to call them
tegmina. The musical powers of the Orthoptera are confined to the
saltatorial group of families.
Fig. 101.—Poecilimon affinis ♂. Bulgaria. Alar organs serving only as
musical organs. The ear on front tibia and aural orifice of prothorax are
well shown.

The Cursoria are dumb or nearly so; it is a remarkable fact that also in
this latter division the alar organs, though frequently present, have but
little value for flight, and are in some cases devoted to what we may call
purposes of ornament or concealment. This is specially the case in the
Phasmidae and Mantidae, where the effectiveness of colour and pattern
of these parts becomes truly astonishing. The tegmina frequently exhibit
an extraordinary resemblance to vegetable structures, and this
appearance is not superficial, for it may be seen that the nervures of the
wings in their disposition and appearance resemble almost exactly the
ribs of leaves. One of the most remarkable of the features of Orthoptera is
that a great difference frequently exists between the colours of the
tegmina and of the wings, i.e. the front and hind wings; the latter are
concealed in the condition of repose, but when activity is entered on and
they are displayed, the individual becomes in appearance a totally
different creature. In some cases, contrary to what usually occurs in
Insects, it is the female that is most remarkable; the male in Mantidae and
Phasmidae being frequently a creature of quite inferior appearance and
power in comparison with his consort. The musical powers of the
saltatorial Orthoptera are, however, specially characteristic of the male
sex. There is evidence that these powers are of great importance to the
creatures, though in what way is far from clear. Some parts of the
structures of the body are in many of these musical species clearly
dominated by the musical organs, and are apparently specially directed to
securing their efficiency. We find in some Locustidae that the tegmina are
nothing but sound-producing instruments, while the pronotum is
prolonged to form a hood that protects them without encumbering their
action. In the males of the Pneumorides, where the phonetic organ is
situated on the abdomen, this part of the body is inflated and tense, no
doubt with the result of increasing the volume and quality of the sound. In
the genus Methone (Fig. 185) we find a grasshopper whose great hind
legs have no saltatorial function, and but little power of locomotion, but
act as parts of a sound-producing instrument, and as agents for
protecting some parts of the body in repose. Further particulars of these
cases must be looked for in our accounts of the different groups.

The eggs of many Orthoptera are deposited in capsules or cases; these


capsules may contain only one egg, or a great many.

The Order includes many species of Insects, though in Britain it is poorly


represented: we have only about forty species, and this small number
includes some that are naturalised. Only a few of the forty extend their
range to Scotland. A revision of the species found in Britain has recently
been made by Mr. Eland Shaw.[127] In continental Europe, especially in
the south, the species become more numerous; about 500 are known as
inhabitants of geographical Europe. In countries where the face of nature
has been less transformed by the operations of man, and especially in the
tropical parts of the world, Orthoptera are much more abundant.

The lowest number at which the species now existing on the surface of
the earth can be estimated is 10,000. This, however, is probably far under
the mark, for the smaller and more obscure species of Orthoptera have
never been thoroughly collected in any tropical continental region, while
new forms of even the largest size are still frequently discovered in the
tropics.

We shall treat the Order as composed of eight families:—

1. Forficulidae—Tegmina short, wings complexly


folded; body armed at the extremity with
strong forceps.
Series, Cursoria: 2. Hemimeridae—Apterous: head exserted,
hind legs but constricted behind.
little different 3. Blattidae—Coxae of the legs large, exserted,
from the protecting the lower part of the body.
others. 4. Mantidae—Front legs very large, raptorial,
armed with spines.
5. Phasmidae—Mesothorax large as compared
with the prothorax.
Series, Saltatoria: 6. Acridiidae—Antennae short, not setaceous, of
hind legs not more than 30 joints, tarsi three-jointed.
elongate, 7. Locustidae—Antennae very long, setaceous,
formed for composed of a large number of joints, tarsi
leaping, their four-jointed.
femora usually 8. Gryllidae—Antennae very long, setaceous,
thickened. tarsi two- or three-jointed.

The first five of these subdivisions are amongst the most distinct of any
that exist in the Insecta, there being no connecting links between them.
The three groups forming the Saltatoria are much more intimately allied,
and should, taken together, probably have only the same taxonomic value
as any one of the other five groups.

Owing partly to the inherent difficulties of the subject, and partly to the
fragmentary manner in which it has been treated by systematists, it has
been impossible till recently to form any clear idea of the classification of
Orthoptera. During the last twenty years Henri de Saussure and Brunner
von Wattenwyl have greatly elucidated this subject. The latter of these
two distinguished naturalists has recently published[128] a revision of the
system of Orthoptera, which will be of great assistance to those who may
wish to study these Insects. We therefore reproduce from it the characters
of the tribes, placing the portion relating to each family at the end of our
sketch thereof.

Fam. I. Forficulidae—Earwigs.

(DERMAPTERA OR DERMATOPTERA OF BRAUER AND OTHERS)


Insects of elongate form, with an imbricate arrangement of the segments of the
body; bearing at the posterior extremity a pair of callipers or more distorted
instruments. The hind wings (when present) folded in a complex manner, and
covered, except at their tips, by a pair of short wing-covers (tegmina), of a leather-
like consistence. Wingless forms are very numerous. The young is very similar to
the adult.

Fig. 102.—Pygidicrana hugeli. Java.

Although earwigs are said to be rare in most parts of the world, yet in
Europe no Insect is better known than Forficula auricularia, the
common earwig, it being very abundant even in gardens and
cultivated places. In certain seasons it not unfrequently enters our
houses, in which case it too often falls a victim to prejudices that
have very little to justify them. This Insect is a good type of the
winged earwigs. In the parts of the mouth it exhibits the structures
usual in the Orthoptera; there is a large labrum, a pair of maxillae,
each provided with two lobes and a palpus consisting of two very
short basal joints and three longer joints beyond these; the
mandibles are strong, with curvate pointed extremities; in the lower
lip there is a ligula exposed in front of a very large mentum; it
consists of two pieces, not joined together along the middle, but
each bearing on its lateral edge a palpus with two elongate joints
and a short basal one; this lip is completed by the lingua, which
reposes on the upper face of the part, and completely overlaps and
protects the chink left by the want of union along the middle line of
the external parts of the lip. The antennae are elongate, filiform, and
are borne very near the front of the exserted head. There are rather
large facetted eyes, but no ocelli. The three segments of the thorax
are distinct, the prothorax being quite free and capable of movement
independent of the parts behind it: the meso- and meta-nota are
covered by the tegmina and wings; these latter project slightly from
underneath the former in the shape of small slips, that are often of
rather lighter colour; the wing-covers are short, not extending beyond
the insertion of the hind legs, and repose flat on the back, meeting
together in a straight line along the middle. These peculiar flat,
abbreviated wing-covers, with small slips (which are portions of the
folded wings) projecting a little from underneath them, are distinctive
marks of the winged Forficulidae.

The legs are inserted far from one another, the coxae being small;
each sternum of the three thoracic segments projects backwards,
forming a peculiar long, free fold, underlapping the front part of the
following segment. The hind body or abdomen is elongate, and is
formed of ten segments; the number readily visible being two less in
the female than it is in the male. The segments are fitted together by
a complex imbrication, which admits of great mobility and distension,
while offering a remarkable power of resistance to external pressure:
each segment is inserted far forward in the interior of that preceding
it, and each also consists of separate upper and lower plates that
much overlap where they meet at the sides (see Fig. 103). The body
is always terminated by a pair of horny, pincer-like processes, which
are differently shaped according to the sex of the individual.

Fig. 103.—Lateral view of Forficula auricularia L. Female abdomen


distended showing spiracles, S, and the small 8th and 9th dorsal
plates (7 and 8 in Fig.).

The structure of the abdomen in the earwig has given rise to


considerable discussion. In Fig. 103 we reproduce Westwood's
diagram of it as seen fully distended in a female specimen; in this
state the minute spiracles can be detected, though in the normal
condition of the body they cannot be seen, being placed on the
delicate membranes that connect the chitinous plates. Westwood's
interpretation of the structure was not, however, quite correct, as the
part which he considered to be the first dorsal plate is really the
second; so that the segments numbered 7, 8, 9 in our figure are
really 8, 9, 10. The common earwig is interesting as exhibiting, in an
imperfect state, the union of the first dorsal plate of the abdomen
with the thorax; a condition which is carried to so great an extent in
the Hymenoptera as to quite obscure the nature of the parts, and
which has consequently given rise to much perplexity and
discussion. We represent this structure as seen in the common
earwig in Fig. 104, where a represents the pronotum, b the
mesonotum, c the metanotum, d the first, f the second abdominal
segment; e being a delicate membrane of considerable size that
intervenes between the two, and which is more exposed than are the
corresponding membranes connecting the subsequent rings; a
condition similar to that which is found in Cimbex, Cephus, and some
other Hymenoptera.

Fig. 104.—Dorsal portions of the middle segments of body of Forficula


auricularia (tegmina and wings removed).

On the under surface of the abdomen of the earwig the full number
of 10 plates cannot be superficially distinguished; but it is found by
dissection that in the female the short eighth and ninth dorsal rings
are joined on the ventral aspect by a delicate membrane, while the
tenth ventral is of a less delicate nature, and forms a triangular plate
at the base of each half of the forceps. Between the branches of the
forceps there is a perpendicular plate, the pygidium of Orthopterists,
possibly the unpaired terminal portion of the body seen in some
embryos, and called the telson. The pygidium is a separate sclerite,
though it looks as if it were only a portion of the large tenth dorsal
plate bent downwards, and in some descriptive works is erroneously
described as being such.
Fig. 105.—Chelidura dilatata, male. Pyrenees.

Fig. 106.—Tegmina and wings (visible in part or invisible) of apterous


earwigs. 1, Chelidura sp.; 2, Chelidura dilatata; 3, Anisolabis
moesta; 4. A. maritima. a, First thoracic segment; b, second; c,
third; d, basal portion of abdomen.

A very large number of species of Forficulidae have the organs of


flight undeveloped. Fig. 105 represents Chelidura dilatata, an
apterous form that is very common in the Eastern Pyrenees. The
condition of the meso- and meta-nota—the parts from which the
tegmina and wings are developed, and to which they are attached
when present—is very remarkable in these forms, and exhibits much
variety. In Fig. 106 we represent the conditions of these parts in a
few apterous forms. The tegmina or the segment from which they
are developed (b), are seen in the shape of a plate which may
extend all across the middle and be undivided (No. 4); in which case
the appearance indicates entire absence of the tegmina; these are,
on the contrary, evidently present in the form of slips grafted one to
each side of the second thoracic segment in Anisolabis (No. 3); or
they may look like short broad slips extending all across the body,
and marking off a piece frequently called a scutellum, but which is
really the mesonotum (some species of Chelidura, as No. 2); or,
again, they may be nearly free tegmina, somewhat similar to those of
the winged forms; this is the case with some species of Chelidura, as
represented by No. 1. This last figure is taken from a species from
the Sierra Nevada, apparently undescribed, allied to C. bolivari.

In the cases we are considering no analogous structures exist on the


metanotum (the part of the body that in the winged forms bears the
wings, and which is marked c in our diagrams, Fig. 106), so that the
tegmina are to all appearance less rudimentary (or vestigial) than the
wings. The metanotum forms a sort of flap, called by Fischer[129]
"involucrum alarum"; he considered the part immediately behind this
to be the metanotum; this piece is, however, no doubt really part of
the abdomen (d in our Figure). This is apparently the view taken by
Brunner.[130] The structure of these parts is important as bearing on
the subject of the nature and origin of Insects' wings, a question to
which no satisfactory answer has yet been given. The appearances
we have remarked on are to some extent similar to the conditions
existing in the immature state of the organs of flight in the common
earwig (see Fig. 112, p. 212), but whether the varieties presented by
the wingless forms have parallels in the immature conditions of the
various winged forms is quite uncertain, the life-histories of earwigs
being almost unknown.

Fig. 107.—Wing of Forficula auricularia. A, Wing expanded,


explanation in text; B, wing folded and packed.

The developed wings of earwigs are worthy of attention, both as


regards their actual structure and the manner in which they are
folded up in repose. When expanded they have a shape curiously
suggestive of the human ear. The chief parts of the wing, as shown
in Fig. 107, A, are a, b, two portions of the horny piece that forms the
scale which covers the more delicate parts of the wing when it is
folded, and which, according to Brunner, represents the radial and
ulnar fields of the wings of Acridiidae and Locustidae (see Fig. 167);
c is the small apical field limited below by the vena dividens; d is the
vena plicata which runs along the under side of the scale as far as
the apical field, where it gives off the axillary nerves; e is a vena
spuria, or adventitious vein such as exists in many other Orthoptera
with delicate wings. On the front part of the scale, a, and on a
different plane so that it is not shown in our figure, there is a very
delicate small band which is supposed to represent the marginal field
of the wing of other Orthoptera. There are, however, grave difficulties
in the way of accepting this view of the earwig's wing, amongst
which we may mention the position of the vena dividens and its
relation to the so-called radial and ulnar fields of the wing. The wings
are remarkable for their delicacy; moreover, the way in which they
fold up so as to be packed in the manner shown in B, Fig. 107, is
very interesting, there being, in fact, no other Insects that fold up
their wings in so complicated and compact a fashion as the earwigs
do. The process is carried out somewhat as follows: the longer radii
come a little nearer together, the delicate membrane between them
falling into folds somewhat like those of a paper fan; a transverse
fold, or turn-over, then occurs at the point where the radii, or axillary
nerves, start from the vena plicata; then a second transverse fold,
but in a reversed direction, occurs affecting the wing just close to the
spots where the shorter radial nervures are dilated; then by a
contraction close to the scale the whole series of complex folds and
double are brought together and compressed.

It is quite a mystery why earwigs should fold their wings in this


complex manner, and it is still more remarkable that the Insects very
rarely use them. Indeed, though Forficula auricularia is scarcely
surpassed in numbers by any British Insect, yet it is rarely seen on
the wing; it is probable that the majority of the individuals of this
species may never make use of their organs of flight or go through
the complex process of unfolding and folding them. It should be
remarked that no part of the delicate membranous expanse of the
wing is exposed when the wings are packed in their position of
repose; for the portion that projects from under the tegmina—and
which, it will be remembered, is always present, for when wings exist
in earwigs they are never entirely concealed by the tegmina—is, it is
curious to note, of hard texture, and is frequently coloured and
sculptured in harmony with the tegmen; in fact, one small part of the
wing forms in colour and texture a most striking contrast to the rest
of the organ, but agrees in these respects with the wing-covers. This
condition is seen in Fig. 108, where B shows the sculpture of the
tegmina t, and of the projecting tips of the wings w. There are
numerous other instances in Orthoptera where one part of a wing or
wing-case is exposed and the other part concealed, and the exposed
portion is totally different in colour and texture from the concealed
portion.

The wings of earwigs are attached to the body in a very unusual


manner; each wing is continued inwards on the upper surface of the
metanotum, as if it were a layer of the integument meeting its fellow
on the mesial line; the point of contact forming two angles just
behind the metanotum.

Some writers have considered that the tegmina of earwigs are not
the homologues of those of other Orthoptera, but are really tegulae
(cf. Fig. 56, p. 103). We are not aware that any direct evidence has
been produced in support of this view.

The pair of forceps with which the body is armed at its extremity
forms another character almost peculiar to the earwigs, but which
exists in the genus Japyx of the Thysanura. These forceps vary
much in the different genera of the family; they sometimes attain a
large size and assume very extraordinary and distorted shapes.
They are occasionally used by the Insects as a means of completing
the process of packing up the wings, but in many species it is not
probable that they can be used for this purpose, because their great
size and peculiarly distorted forms render them unsuitable for
assisting in a delicate process of arrangement; they are, too, always
present in the wingless forms of the family. Their importance to the
creature is at present quite obscure; we can only compare them with
the horns of Lamellicorn Coleoptera, which have hitherto proved
inexplicable so far as utility is concerned. No doubt the callipers of
the earwigs give them an imposing appearance, and may be of
some little advantage on this account; they are not known to be used
as offensive instruments for fighting, but they are occasionally
brought into play for purposes of defence, the creatures using them
for the infliction of nips, which, however, are by no means of a
formidable character.

Fig. 108.—Anechura scabriuscula. Himalaya. A, Outline of the Insect;


B, tegmina, t, and tips of wings, w, showing their similar sculpture.

These forceps are, in the case of the common earwig—and they


have not been studied from this point of view in any other species—
remarkable, because of the great variation in their development in
the male, a character which again reminds us of the horns of
Lamellicorn beetles: in the female they are comparatively invariable,
as is also the case in the few species of Lamellicornia, which
possess horned females. A and B in Figure 109 represent the
forceps of different males of the common earwig, C showing those of
the other sex. The subject of the variation of the male callipers of the
earwig has been considered by Messrs. Bateson and Brindley,[131]
who examined 1000 specimens captured on the same day on one of
the Farne islands off the coast of Northumberland; 583 of these were
mature males, and the pincers were found to vary in length from
about 2½ mm. to 9 mm. (A and B in Fig. 109 represent two of the
more extreme forms of this set of individuals.) Specimens of medium
size were not, as it might perhaps have been expected they would
be, the most common; there were, in fact, only about 12 individuals
having the forceps of the medium length—4¾ to 5¼ mm., while
there were no less than 90 individuals having forceps of a length of
about 7 mm., and 120 with a length of from 2¾ to 3¼. Males with a
medium large length of the organ and with a medium small length
thereof were the most abundant, so that a sort of dimorphism was
found to exist. Similar relations were detected in the length of the
horns of the male of a Lamellicorn beetle examined by these
gentlemen. In the case of the set of earwigs we have mentioned,
very little variation existed in the length of the forceps in the female
sex.

Fig. 109.—Forceps of the common earwig: A, of large male; B, of small


male; C, of female.

In many earwigs—including F. auricularia—there may be seen on


each side of the dorsal aspect of the true fourth, or of the fourth and
neighbouring segments of the hind body a small elevation, called by
systematists a plica or fold, and on examination the fold will be found
to possess a small orifice on its posterior aspect. These folds are
shown in Figs. 105 and 108; they have been made use of for
purposes of classification, though no functional importance was
attached to them. Meinert, however, discovered[132] that there are
foetid glands in this situation, and Vosseler has recently shown[133]
that the folds are connected with scent-glands, from which proceed,
in all probability, the peculiar odour that is sometimes given off by the
earwig. The forms destitute of the folds, e.g. Labidura, are
considered to have no scent glands. There is a very peculiar series
of smooth marks in the earwigs on the dorsal aspect of the
abdominal segments, and these are present in the glandless forms
as well as in the others.

The internal anatomy has been to some extent investigated by


Dufour and Meinert. Dufour dissected F. auricularia and Labidura
riparia, and found[134] that salivary glands exist in the latter Insect
(called by him Forficula gigantea), though he was unable to discover
them in the common earwig. According to Meinert,[135] there are,
however, salivary glands affixed to the stipes of the maxillae in F.
auricularia, while (in addition?) L. riparia possesses very elongate
glands seated in the middle or posterior part of the breast. The
alimentary canal is destitute of convolutions, but oesophagus, crop,
and gizzard all exist, and the intestine behind the stomach consists
of three divisions. The Malpighian tubes are numerous, 30 or 40, and
elongate. The respiratory system is not highly developed. Earwigs—
the European species at least—have, as already mentioned, very
small powers of flight; the tracheal system is correspondingly small,
and is destitute of the vesicular dilatations that are so remarkable in
the migratory Locusts.

Fig. 110.—Labidura riparia, male. Europe.

The three thoracic spiracles[136] are readily observed in living


individuals. There are seven pairs of abdominal spiracles, which,
however, are very minute, and can only be found by distending the
body as shown in Fig. 103. The ventral chain consists of nine ganglia
(the sub-oesophageal centre is not alluded to by Dufour); the three
thoracic are equidistant and rather small; the hindmost of the six
abdominal ganglia is considerably larger than any one of the other
five.

The ovaries of Labidura riparia and Forficula auricularia are


extremely different. In L. riparia there are on each side five tubes,
each terminating separately in an obliquely directed lateral part of
the oviduct. In F. auricularia there is but one tube on each side, but it
is covered by three longitudinal series of very short sub-sessile,
grape-like bodies, each of the two tubes being much dilated behind
the point where these bodies cease.
The testes in earwigs are peculiar and simple; they consist, on each
side, of a pair of curvate tubular bodies, connected at their bases
and prolonged outwards in the form of an elongate, slender vas
deferens. The structures in the males of several species have been
described at some length by Meinert,[137] who finds that in some
species a double ejaculatory duct exists.

Fig. 111.—Ovaries of Labidura riparia, A; and Forficula auricularia, B.


(After Dufour.)

The young is similar to the adult in form; in the winged forms it is


always easy to distinguish the adult by the full development of the
wings, but in the wingless forms it can only be decided with certainty
that a specimen is not adult by the softer and weaker condition of the
integuments. Scarcely anything appears to be known as to the life-
history, except a few observations that have been made on the
common earwig; Camerano found[138] that this Insect has certainly
three ecdyses, and possibly an earlier one which he failed to notice,
and his observation confirms the vague previous statement of
Fischer. The eggs, in the neighbourhood of Turin, are deposited and
hatched in the early spring; in one case they were laid on the 10th
March, and the Insects issuing from them had completed their
growth and were transformed into perfect Insects on the 22nd May.
In the immature state the alar structures of the future imago may be
detected. The tegmina-bearing sclerites, t, Fig. 112, look then
somewhat like those of some of the apterous forms (Fig. 106) and,
as shown in A and B, Fig. 112, do not differ greatly in the earlier and
later stages. The wings, however, change much more than the

You might also like