ebook img

Computer Graphics Through OpenGL: From Theory to Experiments PDF

761 Pages·2019·291.01 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Computer Graphics Through OpenGL: From Theory to Experiments

 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 PREFACE XVII ABOUT THE AUTHOR XXVII I Hello World 1 1 AN INVITATION TO COMPUTER GRAPHICS 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 ON TO OPENGL AND 3D COMPUTER GRAPHICS 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 AN OPENGL TOOLBOX 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 TRANSFORMATION, ANIMATION AND VIEWING 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 INSIDE ANIMATION: THE THEORY OF TRANSFORMATIONS 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 ADVANCED ANIMATION TECHNIQUES 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 CONVEXITY AND INTERPOLATION 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 TRIANGULATION 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 ORIENTATION 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

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.