Opengl® on Silicon Graphics Systems
Total Page:16
File Type:pdf, Size:1020Kb
OpenGL® on Silicon Graphics Systems 007-2392-003 CONTRIBUTORS Written by Renate Kempf and Jed Hartman. Revised by Ken Jones. Illustrated by Dany Galgani, Martha Levine, and Chrystie Danzer Production by Allen Clardy and Karen Jacobson Engineering contributions by Allen Akin, Steve Anderson, David Blythe, Sharon Rose Clay, Terrence Crane, Kathleen Danielson, Tom Davis, Celeste Fowler, Ziv Gigus, David Gorgen, Paul Hansen, Paul Ho, Simon Hui, George Kyriazis, Mark Kilgard, Phil Lacroute, Jon Leech, Mark Peercy, Dave Shreiner, Chris Tanner, Joel Tesler, Gianpaolo Tommasi, Bill Torzewski, Bill Wehner, Nancy Cam Winget, Paula Womack, David Yu, and others. Some of the material in this book is from “OpenGL from the EXTensions to the SOLutions,” which is part of the developer’s toolbox. St. Peter’s Basilica image courtesy of ENEL SpA and InfoByte SpA. Disk Thrower image courtesy of Xavier Berenguer, Animatica. COPYRIGHT © 1996, 1998, 2005 Silicon Graphics, Inc. All rights reserved; provided portions may be copyright in third parties, as indicated elsewhere herein. No permission is granted to copy, distribute, or create derivative works from the contents of this electronic documentation in any manner, in whole or in part, without the prior written permission of Silicon Graphics, Inc. LIMITED RIGHTS LEGEND The software described in this document is "commercial computer software" provided with restricted rights (except as to included open/free source) as specified in the FAR 52.227-19 and/or the DFAR 227.7202, or successive sections. Use beyond license provisions is a violation of worldwide intellectual property laws, treaties and conventions. This document is provided with limited rights as defined in 52.227-14. TRADEMARKS AND ATTRIBUTIONS Silicon Graphics, the Silicon Graphics logo, Fuel, InfiniteReality, IRIS, IRIS Indigo, IRIX, OpenGL, and Tezro are registered trademarks and Developer Magic, IMPACT, IRIS GL, IRIS InSight, IRIS ViewKit, Elan, Express, Indy, Indigo, Indigo2, Indigo2 IMPACT, Indigo2 High IMPACT, Indigo2 Maximum IMPACT, InfinitePerformance, O2, Onyx, Onyx4, Open Inventor, OpenGL Performer, R8000, R10000, RapidApp, RealityEngine, SGI ProPack, Silicon Graphics Prism, UltimateVision, and VPro are trademarks of Silicon Graphics, Inc. ATI is a registered trademark of ATI Technologies, Inc. Extreme is a trademark used under license by Silicon Graphics Inc. GNOME is a trademark of the GNOME Foundation. Intel and AGP are registered trademarks and Itanium is a trademark of Intel Corporation. Linux is a registered trademark of Linus Torvalds. MIPS is a registered trademark of MIPS Technologies, Inc. OS/2 is a trademark of International Business Machines Corporation. Windows NT is a trademark and Microsoft and Windows are registered trademarks of Microsoft Corporation. Motif and OSF/Motif are trademarks of Open Software Foundation. X Window System is a trademark of The Open Group. XFree86 is a trademark of the XFree86 Project, Inc. All other trademarks mentioned herein are the property of their respective owners. New Features in This Guide In addition to miscellaneous changes throughout, this revision includes the following changes: General Changes The guide now reflects OpenGL 1.3, GLX 1.3, and GLU 1.3 and current Silicon Graphics visualization systems. Many of the changes reflect support for Silicon Graphics Onyx4 UltimateVision systems on IRIX and Silicon Graphics Prism systems on Linux. New Chapters • Chapter 7, “Vertex Processing Extensions” • Chapter 13, “Vertex and Fragment Program Extensions” Extensions Deprecated The functionality of the following extensions is now integrated into OpenGL, GLX, and GLU but the extensions remain in this guide for reference by developers using older Silicon Graphics systems—such as VPro, InfinitePerformance, and InfiniteReality: Resource control extensions Make current read, framebuffer configuration, and pixel buffer Texturing extensions Texture objects, subtexture, copy texture, 3D texture, texture edge/border clamp, texture LOD, texture environment add, and texture LOD bias Rendering extensions Blending extensions, multisample, point parameters, shadow, and depth texture Imaging extensions Blend logic op, convolution, histogram and minmax, packed pixels, color matrix, and color table Miscellaneous extensions Polygon offset, vertex array, NURBS tesselator, and object space tesselator 007-2392-003 iii New Features in This Guide Extensions Added: ARB_depth_texture ATI_envmap_bumpmap ARB_fragment_program ATI_fragment_shader ARB_imaging ATI_map_object_buffer ARB_multisample ATI_separate_stencil ARB_multitexture ATI_texture_env_combine3 ARB_point_parameters ATI_texture_float ARB_shadow ATI_texture_mirror_once ARB_shadow_ambient ATI_vertex_array_object ARB_texture_border_clamp ATI_vertex_attrib_array_object ARB_texture_compression ATI_vertex_streams ARB_texture_cube_map EXT_bgra ARB_texture_env_add EXT_blend_func_separate ARB_texture_env_combine EXT_clip_volume_hint ARB_texture_env_crossbar EXT_compiled_vertex_array ARB_texture_env_dot3 EXT_copy_texture ARB_texture_mirrored_repeat EXT_draw_range_elements ARB_transpose_matrix EXT_fog_coord ARB_vertex_blend EXT_multi_draw_arrays ARB_vertex_buffer_object EXT_point_parameters ARB_vertex_program EXT_polygon_offset ARB_window_pos EXT_rescale_normal ATIX_texture_env_combine3 EXT_secondary_color ATIX_texture_env_route EXT_separate_specular_color ATIX_vertex_shader_output_point_size EXT_stencil_wrap ATI_draw_buffers EXT_subtexture ATI_element_array EXT_texgen_reflection iv 007-2392-003 New Features in This Guide EXT_texture NV_texgen_reflection EXT_texture3D S3_s3tc EXT_texture_compression_s3tc SGIS_generate_mipmap EXT_texture_cube_map SGIS_multitexture EXT_texture_edge_clamp SGIS_pixel_texture EXT_texture_env_add SGIS_texture_color_mask EXT_texture_env_combine SGIS_texture_lod EXT_texture_env_dot3 SGIX_async EXT_texture_filter_anisotropic SGIX_async_pixel EXT_texture_lod_bias SGIX_blend_alpha_minmax EXT_texture_object SGIX_convolution_accuracy EXT_texture_rectangle SGIX_fragment_lighting EXT_vertex_array SGIX_resample EXT_vertex_shader SGIX_scalebias_hint HP_occlusion_test SGIX_subsample INGR_interlace_read SGIX_texture_coordinate_clamp NV_blend_square SGIX_vertex_preclip NV_occlusion_query SUN_multi_draw_arrays NV_point_sprite 007-2392-003 v Record of Revision Version Description 001 1996 Original publication. 002 1998 Updated to support OpenGL 1.1. 003 March 2005 Updated to support OpenGL 1.3 and extensions to support Onyx4 and Silicon Graphics Prism systems. 007-2392-003 vii Contents Figures . xxxi Tables . xxxiii Examples . xxxv About This Guide. xxxvii Silicon Graphics Visualization Systems . xxxvii What This Guide Contains . .xxxviii What You Should Know Before Reading This Guide . xl Background Reading . xl OpenGL and Associated Tools and Libraries . .xl X Window System: Xlib, X Toolkit, and OSF/Motif . xli Other Sources . xli Obtaining Publications . xlii Conventions Used in This Guide . xlii Typographical Conventions . xlii Function Naming Conventions . xliii Reader Comments . xliv 1. OpenGL on Silicon Graphics Systems. 1 Using OpenGL with the X Window System . 1 GLX Extension to the X Window System . 2 Libraries, Tools, Toolkits, and Widget Sets . 2 Open Inventor . 3 IRIS ViewKit . 4 IRIS IM Widget Set . 4 Xlib Library . 5 Porting Applications between IRIX and Linux . 5 Extensions to OpenGL . 5 007-4075-001 ix Contents Debugging and Performance Optimization . .6 Debugging Your Program . 7 Maximizing Performance With OpenGL Performer . 7 Location of Example Source Code (IRIX-Specific) . .7 2. OpenGL and X: Getting Started . 9 Background and Terminology . 9 X Window System on Silicon Graphics Systems . 9 Silicon Graphics X Servers . 10 GLX Extension to X . 11 Compiling With the GLX Extension . 11 X Window System Concepts . 11 GLX and Overloaded Visuals . 12 GLX Drawables—Windows and Pixmaps . 13 Rendering Contexts . 13 Resources As Server Data . 13 X Window Colormaps . 14 Libraries, Toolkits, and Tools . 14 Widgets and the Xt Library . 15 Xt Library . 15 For More Information About Xt. 16 Other Toolkits and Tools . 16 Integrating Your OpenGL Program With IRIS IM . 16 Simple Motif Example Program . 16 Looking at the Example Program . 19 Opening the X Display . 20 Selecting a Visual . 21 Creating a Rendering Context . .23 Creating the Window. 23 Binding the Context to the Window . 24 Mapping the Window . 24 Integrating OpenGL Programs With X—Summary . 25 x 007-4075-001 Contents Compiling With OpenGL and Related Libraries . 26 Link Lines for Individual Libraries . 26 Link Lines for Groups of Libraries . 27 3. OpenGL and X: Examples . 29 Using Widgets . 29 About OpenGL Drawing-Area Widgets . 30 Drawing-Area Widget Setup and Creation . 31 Setting Up Fallback Resources . 31 Creating the Widgets . 32 Choosing the Visual for the Drawing-Area Widget . 33 Creating Multiple Widgets With Identical Characteristics . 33 Using Drawing-Area Widget Callbacks . 34 Input Handling With Widgets and Xt . 37 Background Information . 37 Using the Input Callback . 37 Using Actions and Translations . 39 Creating Colormaps . 40 Widget Troubleshooting . 40 Keyboard Input Disappears . 40 Inheritance Issues . 41 Using Xlib . 42 Simple Xlib Example Program . 43 Creating a Colormap and a Window . 45 Installing the Colormap . 47 Xlib Event Handling . 48 Handling Mouse Events. 48 Exposing a Window . 50 Using Fonts and Strings . 51 007-4075-001 xi Contents 4. OpenGL and X: Advanced Topics . 55 Using Animations . 55 Swapping Buffers . 56 Controlling an Animation With Workprocs . 57 General