Opengl Distilled / Paul Martz
Total Page:16
File Type:pdf, Size:1020Kb
Page left blank intently OpenGL® Distilled By Paul Martz ............................................... Publisher: Addison Wesley Professional Pub Date: February 27, 2006 Print ISBN-10: 0-321-33679-8 Print ISBN-13: 978-0-321-33679-8 Pages: 304 Table of Contents | Inde OpenGL opens the door to the world of high-quality, high-performance 3D computer graphics. The preferred application programming interface for developing 3D applications, OpenGL is widely used in video game development, visuali,ation and simulation, CAD, virtual reality, modeling, and computer-generated animation. OpenGL® Distilled provides the fundamental information you need to start programming 3D graphics, from setting up an OpenGL development environment to creating realistic te tures and shadows. .ritten in an engaging, easy-to-follow style, this boo/ ma/es it easy to find the information you0re loo/ing for. 1ou0ll quic/ly learn the essential and most-often-used features of OpenGL 2.0, along with the best coding practices and troubleshooting tips. Topics include Drawing and rendering geometric data such as points, lines, and polygons Controlling color and lighting to create elegant graphics Creating and orienting views Increasing image realism with te ture mapping and shadows Improving rendering performance Preserving graphics integrity across platforms A companion .eb site includes complete source code e amples, color versions of special effects described in the boo/, and additional resources. Page left blank intently Table of contents: Chapter 6. Texture Mapping Copyright ............................................................... 4 Section 6.1. Using Texture Maps ........................... 138 Foreword ............................................................... 6 Section 6.2. Lighting and Shadows with Texture .. 155 Preface ................................................................... 7 Section 6.3. Debugging .......................................... 169 About the Book ..................................................... 8 Section 6.4. More Information ............................... 173 Intended Audience ................................................. 10 Section 6.5. References .......................................... 174 Format of the Book ............................................... 11 Conventions ........................................................... 12 Chapter 7. Extensions and Versions OpenGL® Distilled Web Site ............................... 13 Section 7.1. Extensions .......................................... 176 Acknowledgments ................................................. 14 Section 7.2. Versions ............................................. 181 About the Author ................................................... 15 Section 7.3. Extension- and Version-Safe Code .... 183 Section 7.4. More Information ............................... 187 Chapter 1. An Introduction to OpenGL Section 1.1. What Is OpenGL? .............................. 18 Chapter 8. Platform-Specific Interfaces Section 1.2. GLUT ................................................ 30 Section 8.1. Concepts ............................................. 190 Section 1.3. GLU ................................................... 31 Section 8.2. Apple Mac OS X ................................ 191 Section 1.4. Development Environment ................32 Section 8.3. Linux .................................................. 195 Section 1.5. A Simple Example .............................35 Section 8.4. Microsoft Windows ............................200 Section 1.6. History of OpenGL ............................ 39 Section 8.5. More Information ............................... 204 Section 1.7. More Information .............................. 42 Section 8.6. References .......................................... 205 Section 1.8. References ......................................... 43 Appendix A. Other Features Chapter 2. Drawing Primitives Section A.1. Multisample ...................................... 207 Section 2.1. OpenGL Primitives ............................46 Section A.2. Occlusion Queries ............................. 208 Section 2.2. Specifying Vertex Data ..................... 49 Section A.3. Fog .................................................... 209 Section 2.3. Drawing Details ................................. 63 Section A.4. Clip Planes ........................................ 210 Section 2.4. Performance Issues ............................ 70 Section A.5. Stencil ............................................... 211 Section 2.5. More Information .............................. 74 Section A.6. The Accumulation Buffer ..................212 Section 2.6. References ......................................... 75 Section A.7. Shading Language ............................. 213 Section A.8. References ......................................... 216 Chapter 3. Transformation and Viewing Section 3.1. Coordinate Systems and Matrices ..... 78 Appendix B. Best Practices Section 3.2. The Transformation Pipeline ............. 83 Section B.1. State ................................................... 218 Section 3.3. Setting the Model-View Matrix .........90 Section B.2. Errors ................................................. 219 Section 3.4. Perspective and Parallel Projections ..93 Section B.3. Precision ............................................ 220 Section 3.5. The Viewport ..................................... 95 Section B.4. Objects ............................................... 224 Section 3.6. Selection ............................................ 96 Section 3.7. More Information .............................. 101 Appendix C. Performance Section 3.8. References ......................................... 102 Section C.1. Measure Performance ........................ 224 Section C.2. Avoid Software Rendering ................ 226 Chapter 4. Lighting Section C.3. Reduce Pipeline Bottlenecks ............. 228 Section 4.1. Overview ........................................... 105 Section C.4. Cull Unseen Geometry ...................... 232 Section 4.2. Normals ............................................. 108 Section C.5. State Changes and Queries ................ 233 Section 4.3. Light Parameters ................................109 Section 4.4. Material Parameters ........................... 111 Appendix D. Troubleshooting and Debugging Section 4.5. Positional and Directional Lights ...... 115 Section D.1. Debugging Tools ............................... 235 Section 4.6. Debugging Lights .............................. 117 Section D.2. OpenGL Errors .................................. 236 Section 4.7. More Information .............................. 120 Section D.3. Debugging a Blank Window ............. 239 Section 4.8. References ......................................... 121 Bibliography .......................................................... 242 Chapter 5. Pixel Rectangles Color Plates ............................................................ 245 Section 5.1. Drawing Pixels .................................. 123 Section 5.2. Reading Pixels ................................... 128 Section 5.3. Copying Pixels .................................. 129 Section 5.4. Performance Issues ............................ 130 Section 5.5. Debugging ......................................... 131 Section 5.6. More Information .............................. 134 Section 5.7. References ......................................... 135 Copyright Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3.10 corpsales1pearsontechgroup.com For sales outside the U.S., please contact: 2nternational Sales international1pearsoned.com 3isit us on the Web: www.awprofessional.com Library of Congress Cataloging-in-Publication Data Mart4, 5aul. OpenG7 distilled 5aul Mart4. p. cm. 2ncludes bibliographical references and index. 2S8N 0-321-33970-8 (pbk. : alk. paper) 1. Computer graphics. 2. OpenG7. 2. Title. T385.M3999 2009 009.9'9dc22 2005039.23 Copyright = 2009 5earson Education, 2nc. All rights reserved. 5rinted in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: 5earson Education, 2nc. Rights and Contracts Aepartment 4 75 Arlington Street, Suite 300 8oston, MA 02119 Fax (917) 8.8-70.7 Text printed in the United States on recycled paper at Courier in Stoughton, Massachusetts. First