P-00[fm] 4107 6/18/03 10:12 AM Page i T O GL HE PEN E G XTENSIONS UIDE P-00[fm] 4107 6/18/03 10:12 AM Page ii LIMITED WARRANTY AND DISCLAIMER OF LIABILITY CHARLES RIVER MEDIA, INC. (“CRM”) AND/OR ANYONE WHO HAS BEEN INVOLVED IN THE WRITING, CREATION OR PRODUCTION OF THE ACCOMPANYING CODE IN THE TEXTUAL MATERIAL IN THE BOOK, CANNOT AND DO NOT WARRANT THE PERFOR- MANCE OR RESULTS THAT MAY BE OBTAINED BY USING THE CONTENTS OF THE BOOK. THE AUTHOR AND PUBLISHER HAVE USED THEIR BEST EFFORTS TO ENSURE THE AC- CURACY AND FUNCTIONALITY OF THE TEXTUAL MATERIAL AND PROGRAMS DE- SCRIBED HEREIN. WE HOWEVER, MAKE NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, REGARDING THE PERFORMANCE OF THESE PROGRAMS OR CONTENTS. THE BOOK IS SOLD “AS IS” WITHOUT WARRANTY (EXCEPT FOR DEFECTIVE MATERIALS USED IN MANUFACTURING THE BOOK OR DUE TO FAULTY WORKMANSHIP). THE AUTHOR, THE PUBLISHER, AND ANYONE INVOLVED IN THE PRODUCTION AND MANUFACTURING OF THIS WORK SHALL NOT BE LIABLE FOR DAMAGES OF ANY KIND ARISING OUT OF THE USE OF (OR THE INABILITY TO USE) THE PROGRAMS, SOURCE CODE, OR TEXTUAL MATERIAL CONTAINED IN THIS PUBLICATION. THIS INCLUDES, BUT IS NOT LIMITED TO, LOSS OF REVENUE OR PROFIT, OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THE PRODUCT. THE SOLE REMEDY IN THE EVENT OF A CLAIM OF ANY KIND IS EXPRESSLY LIMITED TO REPLACEMENT OF THE BOOK, AND ONLY AT THE DISCRETION OF CRM. THE USE OF “IMPLIED WARRANTY” AND CERTAIN “EXCLUSIONS” VARY FROM STATE TO STATE, AND MAY NOT APPLY TO THE PURCHASER OF THIS PRODUCT. P-00[fm] 4107 6/18/03 10:12 AM Page iii T O GL HE PEN ® E G XTENSIONS UIDE Eric Lengyel CHARLESRIVERMEDIA, INC. Hingham,Massachusetts P-00[fm] 4107 6/18/03 10:12 AM Page iv Copyright 2003 by CHARLES RIVER MEDIA, INC. All rights reserved. No part of this publication may be reproduced in any way, stored in a retrieval system of any type, or trans- mitted by any means or media, electronic or mechanical, including, but not limited to, photocopy, recording, or scanning, without prior permission in writingfrom the publisher. Editor: David Pallai Production: Publishers’ Design and Production Services Cover Design: The Printed Image CHARLES RIVER MEDIA, INC. 10 Downer Avenue Hingham, Massachusetts 02043 781-740-0400 781-740-8816 (FAX) [email protected] www.charlesriver.com This book is printed on acid-free paper. Eric Lengyel. The OpenGL Extensions Guide. ISBN: 1-58450-294-0 All brand names and product names mentioned in this book are trademarks or service marks of their respec- tive companies. Any omission or misuse (of any kind) of service marks or trademarks should not be regarded as intent to infringe on the property of others. The publisher recognizes and respects all marks used by com- panies, manufacturers, and developers as a means to distinguish their products. Library of Congress Cataloging-in-Publication Data Lengyel, Eric. The OpenGL extensions guide / Eric Lengyel. p. cm. ISBN 1-58450-294-0 (Hardback : alk. paper) 1. Computer graphics. 2. OpenGL. 3. Computer games—Programming. I. Title. T385.L43 2003 006.6'869—dc21 2003008206 Printed in the United States of America 03 7 6 5 4 3 2 First Edition CHARLES RIVER MEDIA titles are available for site license or bulk purchase by institutions, user groups, corporations, etc. For additional information, please contact the Special Sales Department at 781-740-0400. P-00[fm] 4107 6/18/03 10:12 AM Page v CONTENTS Preface Chapter 1 About OpenGL Extensions 1 Chapter 2 Blending 7 2.1 GL_EXT_blend_color 7 2.2 GL_EXT_blend_minmax 11 2.3 GL_EXT_blend_subtract 13 2.4 GL_EXT_blend_func_separate 15 2.5 GL_NV_blend_square 18 Chapter 3 Texture Environment 21 3.1 GL_ARB_multitexture 21 3.2 GL_ARB_texture_env_add 29 3.3 GL_ARB_texture_env_combine 31 3.4 GL_ARB_texture_env_crossbar 35 3.5 GL_ARB_texture_env_dot3 36 3.6 GL_NV_texture_env_combine4 37 3.7 GL_EXT_texture_lod_bias 39 Chapter 4 Texture Mapping 43 4.1 GL_ARB_texture_cube_map 43 4.2 GL_EXT_texture3D 52 P-00[fm] 4107 6/18/03 10:12 AM Page vi vi CONTENTS 4.3 GL_NV_texture_rectangle 64 4.4 GL_EXT_texture_edge_clamp 71 4.5 GL_ARB_texture_border_clamp 72 4.6 GL_ARB_texture_mirrored_repeat 74 4.7 GL_ATI_texture_mirror_once 75 4.8 GL_EXT_texture_filter_anisotropic 76 4.9 GL_SGIS_texture_lod 79 4.10 GL_SGIS_generate_mipmap 82 4.11 GL_NV_texture_expand_normal 84 Chapter 5 Texture Compression 87 5.1 GL_ARB_texture_compression 87 5.2 GL_EXT_texture_compression_s3tc 108 5.3 GL_NV_texture_compression_vtc 110 Chapter 6 Fragment Shading 113 6.1 GL_NV_register_combiners 113 6.2 GL_NV_register_combiners2 135 6.3 GL_NV_texture_shader 138 6.4 GL_NV_texture_shader2 165 6.5 GL_NV_texture_shader3 170 6.6 GL_ATI_fragment_shader 178 Chapter 7 Vertex Blending 201 7.1 GL_EXT_vertex_weighting 201 7.2 GL_ARB_vertex_blend 208 7.3 GL_ATI_vertex_streams 216 Chapter 8 Array Management 225 8.1 GL_EXT_draw_range_elements 225 P-00[fm] 4107 6/18/03 10:12 AM Page vii CONTENTS vii 8.2 GL_EXT_multi_draw_arrays 228 8.3 GL_ATI_element_array 231 8.4 GL_APPLE_element_array 235 8.5 GL_EXT_compiled_vertex_array 242 8.6 GL_NV_vertex_array_range 244 8.7 GL_NV_vertex_array_range2 250 8.8 GL_APPLE_vertex_array_range 252 Chapter 9 Synchronization 257 9.1 GL_NV_fence 257 9.2 GL_APPLE_fence 263 Chapter 10 Lighting 269 10.1 GL_EXT_separate_specular_color 269 10.2 GL_EXT_secondary_color 272 10.3 GL_EXT_rescale_normal 278 10.4 GL_NV_light_max_exponent 279 Chapter 11 Fog 281 11.1 GL_EXT_fog_coord 281 11.2 GL_NV_fog_distance 286 Chapter 12 Stencil Operations 291 12.1 GL_EXT_stencil_wrap 291 12.2 GL_EXT_stencil_two_side 292 12.3 GL_ATI_separate_stencil 296 Chapter 13 Shadow Mapping 303 13.1 GL_ARB_depth_texture 303 13.2 GL_ARB_shadow 307 P-00[fm] 4107 6/18/03 10:12 AM Page viii viii CONTENTS 13.3 GL_ARB_shadow_ambient 309 13.4 GL_EXT_shadow_funcs 310 Chapter 14 Occlusion Culling 313 14.1 GL_HP_occlusion_test 313 14.2 GL_NV_occlusion_query 316 Chapter 15 Point Rendering 325 15.1 GL_ARB_point_parameters 325 15.2 GL_NV_point_sprite 328 Chapter 16 Pixel Formats 335 16.1 GL_EXT_bgra 335 16.2 GL_EXT_abgr 336 16.3 GL_EXT_packed_pixels 338 16.4 GL_APPLE_packed_pixels 340 16.5 GL_NV_packed_depth_stencil 344 Chapter 17 Miscellaneous 349 17.1 GL_ARB_transpose_matrix 349 17.2 GL_NV_depth_clamp 352 17.3 GL_NV_depth_bounds_test 353 17.4 GL_NV_primitive_restart 357 17.5 GL_NV_half_float 360 Chapter 18 Vertex Programs 373 18.1 GL_ARB_vertex_program 373 18.2 GL_NV_vertex_program 431 18.3 GL_NV_vertex_program1_1 474 18.4 GL_NV_vertex_program2 478 P-00[fm] 4107 6/18/03 10:12 AM Page ix CONTENTS ix Chapter 19 Fragment Programs 503 19.1 GL_ARB_fragment_program 503 19.2 GL_NV_fragment_program 552 Appendix A Program Syntax Specifications 601 A.1 GL_ARB_vertex_program 602 A.2 GL_NV_vertex_program 612 A.3 GL_NV_vertex_program1_1 616 A.4 GL_NV_vertex_program2 617 A.5 GL_ARB_fragment_program 624 A.6 GL_NV_fragment_program 634 Appendix B Extension Index 645 Appendix C Function Index 647 Index 657 P-00[fm] 4107 6/18/03 10:12 AM Page x