Graphics Library Programming Guide Volume I
Total Page:16
File Type:pdf, Size:1020Kb
Graphics Library Programming Guide Volume I Document Number 007-1210-060 Contributors Written by Patricia McLendon Illustrated by Dan Young, Howard Look, and Patricia McLendon Edited by Steven W. Hiatt Production by Derrald Vogt Engineering contributions by John Airey, Kurt Akeley, Dan Baum, Rosemary Chang, Howard Cheng, Tom Davis, Bob Drebin, Ben Garlick, Mark Grossman, Michael Jones, Seth Katz, Phil Karlton, George Kong, Erik Lindholm, Howard Look, Rob Mace, Martin McDonald, Jackie Neider, Mark Segal, Dave Spalding, Gary Tarolli, Vince Uttley, and Rolf Van Widenfelt. © Copyright 1992, Silicon Graphics, Inc.— All Rights Reserved This document contains proprietary and confidential information of Silicon Graphics, Inc. The contents of this document may not be disclosed to third parties, copied, or duplicated in any form, in whole or in part, without the prior written permission of Silicon Graphics, Inc. Restricted Rights Legend Use, duplication, or disclosure of the technical data contained in this document by the Government is subject to restrictions as set forth in subdivision (c) (1) (ii) of the Rights in Technical Data and Computer Software clause at DFARS 52.227-7013 and/or in similar or successor clauses in the FAR, or in the DOD or NASA FAR Supplement. Unpublished rights reserved under the Copyright Laws of the United States. Contractor/manufacturer is Silicon Graphics, Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. Graphics Library Programming Guide Document Number 007-1210-060 Silicon Graphics, Inc. Mountain View, California Silicon Graphics, the Silicon Graphics logo, and IRIS are registered trademarks and IRIS Graphics Library, Geometry Engine, Geometry Pipeline, IRIX, 4D, MicroPixel, Personal IRIS, IRIS Indigo, XS, XS24, Elan, RealityEngine, and SkyWriter are trademarks of Silicon Graphics, Inc. Ada is a registered trademark of the Ada Joint Program of the United States of America Ethernet is a registered trademark of Xerox Corporation OSF/Motif is a trademark of the Open Software Foundation Spaceball is a trademark of Spatial Systems, Inc. UNIX is a registered trademark of AT&T Bell Labs X Window System and Athena Widgets are trademarks of the Massachusetts Institute of Technology. Contents Introduction.................................................................................................xxi How to Use This Guide.............................................................. xxii How to Use the Sample Programs.......................... xxii Typographical Conventions ................................... xxiii What this Guide Contains....................................... xxiii How to Use the On-line Manual Pages.....................................xxv Using Man Pages from the Toolchest......................xxv Using Man Pages from an IRIX Shell ......................xxv Suggestions for Further Reading ............................................. xxvi 1. Graphics Development Environment...................................................1-1 1.1 Using the Graphics Library and System Libraries ...................1-1 1.1.1 System Libraries ..........................................................1-2 1.1.2 Include Files .................................................................1-2 1.2 Using the X Window System.......................................................1-2 1.3 Programming in C.........................................................................1-4 1.3.1 Using the ANSI C Standard.......................................1-4 1.3.2 Compiling C Programs...............................................1-4 1.4 GL Program Structure ..................................................................1-5 1.4.1 Initializing the System ................................................1-6 1.4.2 Getting Graphics Information ...................................1-7 1.4.3 Global State Attributes .............................................1-10 1.4.4 Exiting the Graphics Environment .........................1-10 iii 2. Drawing ........................................................................................................2-1 2.1 Drawing with the GL....................................................................2-1 2.1.1 Vertex Subroutines......................................................2-2 2.1.2 Points.............................................................................2-7 2.1.3 Lines ..............................................................................2-8 2.1.4 Polygons .....................................................................2-12 2.1.5 Point-Sampled Polygons..........................................2-17 2.1.6 Meshes ........................................................................2-21 2.1.7 Controlling Polygon Rendering..............................2-29 2.2 Old-Style Drawing ......................................................................2-30 2.2.1 Basic Shapes ...............................................................2-31 2.2.2 Nonrecommended Old-Style Subroutines ............2-37 3. Characters and Fonts...............................................................................3-1 3.1 Drawing Characters......................................................................3-2 3.1.1 Determining the Current Character Position..........3-2 3.1.2 Drawing Character Strings ........................................3-3 3.1.3 Clipping Character Strings ........................................3-3 3.1.4 Getting Character Information..................................3-4 3.2 Creating a Font ..............................................................................3-7 3.2.1 Defining the Font.........................................................3-9 3.2.2 Selecting the Font ......................................................3-12 3.2.3 Querying the System for Font Information...........3-14 4. Display and Color Modes ........................................................................4-1 4.1 Color Display.................................................................................4-2 4.1.1 Bitplanes .......................................................................4-3 4.1.2 Dithering.......................................................................4-4 4.2 RGB Mode ......................................................................................4-5 4.2.1 Setting and Getting the Current Color in RGB Mode................................................................4-7 4.3 Gouraud Shading ..........................................................................4-8 iv 4.4 Color Map Mode .........................................................................4-15 4.4.1 Setting the Current Color in Color Map Mode...................................................4-17 4.4.2 Getting Color Information in Color Map Mode...................................................4-18 4.4.3 Gouraud Shading in Color Map Mode ..................4-19 4.4.4 Blinking.......................................................................4-21 4.5 Onemap and Multimap Modes.................................................4-22 4.6 Gamma Correction......................................................................4-23 5. User Input ....................................................................................................5-1 5.1 Event Handling .............................................................................5-1 5.1.1 Queueing ......................................................................5-3 5.1.2 Polling ...........................................................................5-7 5.2 Input Devices ...............................................................................5-10 5.2.1 Buttons ........................................................................5-11 5.2.2 Valuators ....................................................................5-12 5.2.3 Keyboard Devices .....................................................5-13 5.2.4 Window Manager Tokens........................................5-14 5.2.5 Spaceball Devices...................................................5-15 5.2.6 Controlling Devices ..................................................5-16 5.3 Video Control...............................................................................5-17 6. Animation.....................................................................................................6-1 6.1 Understanding How Animation Works ....................................6-1 6.1.1 Single Buffer Mode .....................................................6-2 6.1.2 Double Buffer Mode ...................................................6-2 6.2 Creating an Animation.................................................................6-2 6.2.1 Setting Modes for Animation ....................................6-3 6.2.2 Swapping Buffers ........................................................6-3 6.2.3 Swapping Multiple Buffers........................................6-3 6.2.4 Maximizing Animation Performance.......................6-6 v 7. Coordinate Transformations ..................................................................7-1 7.1 Coordinate Systems ......................................................................7-2 7.2 Projection Transformations..........................................................7-4 7.2.1 Perspective Projection.................................................7-4 7.2.2 Window Projection .....................................................7-9 7.2.3 Orthographic Projections .........................................7-10