`OpenGL, Release 1
`
`Programming Guide
`
`__. _+_
`
`OpenGL Architecture Review Board
`Jackie Neider Tom Davis Mason W00
`,flrfii 7r
`
`Petitioner Apple Inc. — EX. 1022, p. 1
`
`Petitioner Apple Inc. - Ex. 1022, p. 1
`
`
`
`OpenGL
`Programming Guide
`The Official Guide to Learning
`OpenGL, Release 1
`
`
`
`San Juan Paris Seoul Milan Mexico City Taipei
`
`Addison-Wesley Publishing Company
`Reading, Massachusetts Menlo Park, California
`New York Don Mills, Ontario Wokingham, England
`Amsterdam Bonn Sydney Singapore Tokyo Madrid
`
`OpenGL Architecture Review Board
`Jackie Neider Tom Davis Mason Woo
`
`A
`VV
`
`Petitioner Apple Inc. — EX. 1022, p. 2
`
`Petitioner Apple Inc. - Ex. 1022, p. 2
`
`
`
`
`
`l
`
`n____..,_._,_e..-_
`
`Silicon Graphics, the Silicon Graphics logo, and IRIS are registered
`trademarks and OpenGL and IRIS Graphics Library are trademarks of
`Silicon Graphics, Inc. X Window System is a trademark of Massachusetts
`Institute of Technology. Display PostScript is a registered trademark of
`Adobe Systems Incorporated.
`
`The authors and publishers have taken care in 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.
`
`Library of Congress Cataloging-in-Publication Data
`
`Neider, Jackie.
`OpenGL programming guide : the official guide to learning OpenGL,
`release 1 / OpenGL Architecture Review Board ;]ackie Neider, Tom
`Davis, Mason Woo.
`p.
`cm.
`Includes index.
`ISBN 0-201—63274-8
`
`ll. Woo,
`1. Davis, Torn.
`2. OpenGL.
`1. Computer graphics.
`Mason.
`III. OpenGL Architecture Review Board.
`IV. Title.
`T385.N435
`1993
`
`006.6' 765—dc20
`
`93-3162
`CIP
`
`Copyright © 1993 by Silicon Graphics, Inc.
`
`All rights reserved. No part of this publication may be reproduced, stored
`in a retrieval system, or transmitted, in any form or by any means,
`electronic, mechanical, photocopying, recording or otherwise, without the
`prior written permission of the publisher. Printed in the United States of
`America. Published simultaneously in Canada.
`
`Authors: Jackie Neider, Tom Davis, and Mason Woo
`Sponsoring Editor: David Rogelberg
`Proiect Editor: Joanne Clapp Fullagar
`Cover Image: Thad Beier
`Cover Design: Jean Seal
`Text Design: Electric Ink, Ltd., and Kay Maitz
`
`Set in 10-point Stone Serif
`
`4 5 6 7 8 9-MA-9998979695
`Fourth printing, April 1995
`
`Petitioner Apple Inc. — EX. 1022 p. 3
`
`Petitioner Apple Inc. - Ex. 1022, p. 3
`
`
`
`The OpenGL graphics system is a software interface to graphics hardware.
`(The GL stands for Graphics Library.) It allows you to create interactive
`
`About This Guide
`
`program and explains essential programming details you need to know
`for subsequent chapters.
`- Chapter 2, ”Drawing Geometric Objects, ” explains how to create a
`three-dimensional geometric description of an object that is eventually
`drawn on the screen.
`
`0 Chapter 4, “Display Lists,” discusses how to store a series of OpenGL
`commands for execution at a later time. You’ll want to use this feature
`to increase the performance of your OpenGL program.
`
`
`
`
`Petitioner Apple Inc. — EX. 1022, p. 4
`
`Petitioner Apple Inc. - Ex. 1022, p. 4
`
`
`
`
`
`
`
`Chapter 5, ”Color,” describes how to specify the color and shading
`method used to draw an object.
`
`Chapter 6, “Lighting,” explains how to control the lighting conditions
`surrounding an object and how that object responds to light (that is,
`how it reflects or absorbs light). Lighting is an important topic, since
`objects usually don’t look three-dimensional until they’re lit.
`The remaining chapters explain how to add sophisticated features to your
`three-dimensional scene. You might choose not to take advantage of many
`of these features until you’re more comfortable with OpenGL. Particularly
`advanced topics are noted in the text where they occur.
`Chapter 7, ”Blending, Antialiasing, and Fog, ” describes techniques
`essential to creating a realistic scene—alpha blending (which aIIOWS
`you to create transparent objects), antialiasing, and atmospheric effects
`(such as fog or smog).
`
`Chapter 8, “Drawing Pixels, Bitmaps, Fonts, and Images,” discusses
`how to work with sets of two-dimensional data as bitmaps or images.
`One typical use for bitmaps is to describe characters in fonts.
`
`Chapter 9, “Texture Mapping, ” explains how to map one- and two-
`dimensional images called textures onto three-dimensional objects.
`Many marvelous effects can be achieved through texture mapping.
`Chapter 10, “The Framebuffer,” describes all the possible buffers that
`can exist in an OpenGL implementation and how you can control
`them. You can use the buffers for such effects as hidden-surface
`elimination, stenciling, masking, motion blur, and depth-of—field
`focusing.
`
`Chapter 11, ”Evaluators and NURBS,” gives an introduction to
`.
`.
`advanced techniques for effic1ently generating curves or surfaces.
`Chapter 12, ‘.‘Selection and Feedback, ” explains how you can use
`OpenGL’s selection mechanism to select an object on the screen. It
`also explains the feedback mechanism, which allows you to collect the
`drawing information OpenGL produces rather than having it be used
`to draw on the screen.
`
`Chapter 13, ”Now That You Know, ” describes how to use OpenGL in
`several clever and unexpected ways to produce interesting results.
`These techniques are drawn from years of experience with the
`technological precursor to OpenGL, the Silicon Graphics IRIS Graphics
`Library.
`
`In a
`
`,
`‘
`
`’1
`
`
`
`math.NAP-1‘5...
`
`HR
`
`F'f‘fiat‘fi‘W-xt-P'y‘h
`
`0
`
`.
`
`0
`
`-
`
`t
`
`Final
`
`Hm
`
`This
`
`parti
`a sm.
`“0pc
`auxi]
`prog;
`you l
`
`vi
`
`About This Guide
`
`Petitioner Apple Inc. — Ex. 1022, p. 5
`
`Petitioner Apple Inc. - Ex. 1022, p. 5
`
`
`
`
`
`so that entry 0 is black, entry 1 is red, entry 2 is green, and so on. Note that
`if the numbers from 0 through 7 are written in binary, the 4 bit is turned
`on whenever layer 3 appears, the 2 bit whenever layer 2 appears, and the
`1 bit whenever layer 1 appears.
`
`To clear the window, set the writemask to 7 (all three layers) and set the
`clearing color to 0. To draw your image, set the color to 7, and then when
`you want to draw something in layer n, set the writernask to n. in other
`types of applications, it might be necessary to selectively erase in a layer, in
`which case you would use the same writemasks as above, but set the color
`to 0 instead of 7.
`
`See ”Masking Buffers” on page 298 for more information about
`writemasks.
`
`Antialiased Characters
`
`Using the standard technique for drawing characters with ngitmapO,
`drawing each pixel of a character is an all-or—nothing affair—the pixel is
`either turned on or not. If you're drawing black characters on a white
`background, for example, the resulting pixels are either black or white,
`never a shade of gray. Much smoother, higher-quality images can be
`achieved if intermediate colors are used when rendering characters (grays,
`in this example).
`
`Assuming that you're drawing black characters on a white background,
`imagine a highly magnified picture of the pixels on the screen, with a
`high-resolution character outline superimposed on it, as shown in the left
`side of Figure 13-1.
`
`. Note that
`11 than do
`
`:0 specify
`15 the
`
`’HA,
`
`011 Want to
`a the
`
`es that can
`:an occur,
`
`ing on the
`run of the
`
`pier map
`
`Airtialinsed Characters
`
`393
`
`Petitioner Apple Inc
`
`. _ EX. 1022, p. 6
`
`Petitioner Apple Inc. - Ex. 1022, p. 6
`
`
`
`
`
`
`
`Figure 13-1 Antialiased Characters
`
`Notice that some of the pixels are completely enclosed by the character's
`outline and should be painted black; some pixels are completely outside
`the outline and should be painted white; but many pixels should ideally be
`painted some shade of gray, where the darkness of the gray corresponds to
`the amount of black in the pixel. If this technique is used, the resulting
`image on the screen looks better.
`
`If speed and memory usage are of no concern, each character can be drawn
`as a small image instead of as a bitmap. If you're using RGBA mode,
`however, this method might require up to 32 bits per pixel of the character
`to be stored and drawn, instead of the one bit per pixel in a standard
`character. Alternatively, you could use one 8-bit index per pixel and
`convert these indices to RGBA by table lookup during transfer. In many
`cases, a compromise is possible that allows you to draw the character with
`a few gray levels between black and white (say, two or three), and the
`resulting font description requires only 2 or 3 bits per pixel of storage.
`
`The numbers in the right side of Figure 13-1 indicate the approximate
`percentage coverage of each pixel: 0 means approximately empty, 1 means
`approximately one-third coverage, 2 means two-thirds, and 3 means
`completely covered. If pixels labeled 0 are painted white, pixels labeled 3
`are painted black, and pixels labeled 1 and 2 are painted one-third and
`two-thirds black, respectively, the resulting character looks quite good.
`Only 2 bits are required to store the numbers 0, 1, 2, and 3, so for 2 bits per
`pixel, four levels of gray can be saved.
`
`There are
`
`dependir
`
`In RGBA
`
`where 1,
`the back;
`0.666)) a
`0.333, 0.:
`3 bitmap
`redrawin
`
`appropri.
`
`ln color:
`
`willing ti
`away wit
`precedin
`in the ch
`
`appears.
`gives daI
`writemai
`
`Z, and d]
`in the fr;
`framebu:
`
`For this 1
`
`passes in
`method
`would re
`
`fifteen p
`
`See “Ma:
`and “Bit
`
`bitmaps.
`
`Try This
`
`0 Can
`
`optii
`men
`
`394
`
`Chapter 13: Now That You Know
`
`Petitioner Apple Inc. - EX. 1022, p. 7
`
`Petitioner Apple Inc. - Ex. 1022, p. 7
`
`
`
`.
`
`i
`
`\ I
`
`n addition, there are several appendices that you will likely find useful:
`c Appendix A, “Order of Operations, " gives a technical overview of the
`operations OpenGL performs, briefly describing them in the order in
`which they occur as an application executes.
`- Appendix B, “OpenGL State Variables,” lists the state variables that
`OpenGL maintains and describes how to obtain their values.
`0 Appendix C, “The OpenGL Utility Library,” briefly describes the
`routines available in the OpenGL Utility Library.
`0 Appendix D, “The OpenGL Extension to the X Window System, ”
`briefly describes the routines available in the OpenGL extension to the
`X Window System.
`
`- Appendix E, “The OpenGL Programming Guide Auxiliary Library, ”
`discusses a small C code library that was written for this book to make
`code examples shorter and more comprehensible.
`0 Appendix F, “Calculating Normal Vectors,” tells you how to calculate
`normal vectors for different types of geometric objects.
`. Appendix G, ”Homogeneous Coordinates and Transformation
`Matrices," explains some of the mathematics behind matrix
`transformations.
`
`0 Appendix H, “Programming Tips, " lists some programming tips based
`on the intentions of the designers of OpenGL that you might find
`useful.
`0 Appendix I, "OpenGL Invariance," describes the pixel-exact
`invariance rules that OpenGL implementations follow.
`Finally, an extensive Glossary defines the key terms used in this guide.
`
`How to Obtain the Sample Code
`
`This guide contains many sample programs to illustrate the use of
`particular OpenGL programming techniques. These programs make use of
`a small auxiliary library that was written for this guide. The section
`"OpenGL-related Libraries” on page 10 gives more information about this
`auxiliary library. You can obtain the source code for both the sample
`programs and the auxiliary library for free via ftp (file-transfer protocol) if
`you have access to the Internet.
`
`How to Obtain the Sample Code
`
`vii
`
`
`
`Petitioner Apple Inc. — EX. 1022, p. 8
`
`Petitioner Apple Inc. - Ex. 1022, p. 8
`
`
`
`For example, the following code represents the inner loop you might use
`to perform such hidden-line removal. Each polygon is outlined in the
`foreground color, filled with the background color, and then outlined
`again in the foreground color. The stencil buffer is used to keep the fill
`color of each polygon from overwriting its outline. To optimize
`performance, the stencil and color parameters are changed only twice per
`loop by using the same values both times the polygon outline is drawn.
`
`glEnable (GL_STENCIL_TEST) ;
`g1Enable(GL_DEPTH_TEST);
`glClear(GL_STENCIL_BUFFER_BITJ;
`ngtencilFunc(GL7ALWAYS, O,
`l);
`ngtenCilOp(GL_INVERT, GL_INVERT, GL_INVERT);
`setkcolor(foreground);
`for (i=0;
`i < max;
`i++l
`outline_polygon(il;
`set_color(background);
`l);
`ngtencilFunc(GL_EQUAL, 0,
`g-lStencilOprL_KEEP, GL_KEE}P, GL_KEEP);
`fill_polygon(i);
`set_color(f0reground);
`l):
`ngtencilFunciGL_ALWAYS, D,
`ngtenCilOp(GL_INVERT, GL_INVERT, GL_INVERT);
`outline_polygon(i):
`
`{
`
`} S
`
`ee “Stencil Test" on page 302.
`
`Texture-Mapping Applications
`
`Texture mapping is quite powerful, and it can be used in some interesting
`ways. Here are a few advanced applications of texture
`mapping:
`
`- Antialiased text—Define a texture map for each character at a relatively
`high resolution, and then map them onto smaller areas using the
`filtering provided by texturing. This also makes text appear correctly
`on surfaces that aren't aligned with the screen, but are tilted and have
`some perspective distortion.
`
`- Antialiased lines—These can be done like antialiased text: Make the
`
`line in the texture several pixels wide, and use the texture filtering to
`antialias the lines.
`
`Texture-Mapping Applications
`
`403
`
`
`
`Joint S and a
`
`by
`
`he plane is given by
`
`a line, and then
`
`ction vector.
`
`as removed, one
`,11 the interiors of
`
`mg the background
`vers any outlines
`nethod would
`
`of the object falls
`1t overlap it in
`
`er. For each
`line both in the
`
`,l the interior,
`r. To avoid doing
`ray to clear it is
`n outline. In this
`e.
`
`J i
`
`
`
`Petitioner Apple Inc. — EX. 1022, p. 9
`
`Petitioner Apple Inc. - Ex. 1022, p. 9
`
`
`
`
`
`Petitioner Apple Inc. - Ex. 1022, p. 10
`
`