Review of OpenGL Basics
Chap. 1 of Orange Book
2
Contents
OpenGL HistoryExecution modelFramebufferStateProcessing PipelineDrawing geometry
Drawing imagesCoordinate transformTexture map
3
History of OpenGL Revisions
Version 1.0 (1992): initial releaseVersion 1.1 (1997): vertex arrays and texture objects.Version 1.2 (1998): 3D textures and an optional set of imaging functionality.Version 1.3 (2001): cube map textures, compressed textures, multitextures, …Version 1.4 (2002): automatic mipmap generation, additional blending functions, internal texture formats for storing depth values for use in shadow computations, support for drawing multiple vertex arrays with a single command, more control over point rasterization, control over stencil wrapping behavior, and various additions to texturing capabilities.Version 1.5 (2003): vertex buffer objects, shadow comparison functions, occlusion queries, and non-power-of-2 textures.
4
OpenGL 2.0 (Sept.2004)
opened up the processing pipeline for user control by providing programmability for both vertex processing and fragment processingOpenGL 2.0 is completely backward compatible with OpenGL 1.5Other features: multiple render targets (rendering to multiple buffers simultaneously), non-power-of-2 textures, point sprites, and separate stencil functionality for front- and back-facing surfaces.
5
Execution Model: client-server
An application program (the client) issues OpenGL commands that are interpreted and processed by an OpenGL implementation (the server). The application program and the OpenGL implementation can execute on a single computer or on two different computers. Some OpenGL state is stored in the address space of the client, but the majority of it is stored in the address space of the server.OpenGL commands are always processed in the order in which they are received by the server
6
State Machine
OpenGL was designed as a state machine. Cumulatively, the state settings define the behavior of the OpenGL rendering pipeline and the way in which primitives are transformed into pixels on the display device.OpenGL state is collected into a data structure called a graphics context. Window-system-specific functions create and delete graphics contexts. Quite a few server-side state values in OpenGL have just two states: on or off, controlled by glEnable and glDisable. Client-side state values (such as pointers that define vertex arrays) are controlled by glEnableClientState and glDisableClientState.OpenGL maintains a server-side stack for pushing and popping any or all of the defined state values. This stack can be manipulated with glPushAttrib and glPopAttrib. Similarly, client state can be manipulated on a second stack with glPushClientAttrib and glPopClientAttrib.glGet is a generic function that can query many of the components of a graphics context.
7
Fixed Functionality of OpenGL
8
Drawing Geometry
Sending geometry vertex-at-a-time Vertex array Display list new in 1.5: VBO, server-sid
e vertex arrayPer-vertex operations: T&L
vertex positions are transformed by the modelview and projection matrices
normals are transformed by the inverse transpose of the upper leftmost 3 x 3 matrix taken from the modelview matrix
texture coordinates are transformed by the texture matrices
lighting calculations are applied to modify the base color
texture coordinates may be automatically generated
color material state is applied
point sizes are computed [how]
T&L : transformation and lighting
9
Drawing Geometry
Primitive assembly vertex data is collected in
to complete primitivesPrimitive processing
clipping, culling, perspective-divide
Rasterization A fragment comprises a w
indow coordinate, depth, and other associated attributes such as color, texture coordinates, and so on.
Size,width,stipple, …
Fragment processing Texture mapping, fog
Per-fragment operations
Scissor, depth, stencil, …
Framebuffer operations
Clear, masking, buffer
10
Images – (known as)pixel rectangles
Pixel unpacking Data of pixel rectangles transferred from memo
ry to OpenGLPixel transfer glDrawPixels, … glReadPixels; glCopyPixels
Rasterize and placement glRasterPos; glPixelZoom
Read control glReadBuffer
11
Coordinate TransformationLight positions are stored within OpenGL as eye coordinatelight positions and surface normals must be in the same coordinate system.
glLoadIdentity; glMultMatrix; gluLookAtglTranslate; glScale; glRotateglPushMatrix; …glOrtho; gluPerspective;glViewport
12
Texture Mapping
Texture Mapping = Texture access + texture applicationTexture unit:
the underlying piece of graphics hardware that performs the various texturing operations.
A texture unit can be enabled for 1D, 2D, 3D, or cube map texturing
Texture object: a name and a texture target (1D,2D,3D,cubemap) associated to a texture unit Texture parameters are then assigned (filters, wrap, …) Texture environment and texgen are not stored in texture o
bjects
13
Texture Mapping
Texture environment: the manner in which a texture value is applied t
o a graphics primitive (replace, modulate, …)Multitexture serially connect texture units glActiveTexture, glMultiTexCoord, …
TexGen Procedurally generate texture coordinates
14
Excursions
Vertex array What’s the significance of “client-side”? glEnableClientStat
e [how they are used to specify geometry] [vertex array object: server-side vertex array]
New OpenGL features Secondary color Compressed texture
Reflection models Blinn-Phong: what’s the halfVector in a light? Hemispheric lighting Cook-Torrance, Oren-Nayar, Ward, Ashikhmin-Shirley
High dynamic range lighting
Explanation, spec, example, tutorial, …sought