an interactive introduction to opengl programming
DESCRIPTION
An Interactive Introduction to OpenGL Programming. Ed Angel Dave Shreiner Vicki Shreiner. Welcome. Today’s Goals and Agenda Describe OpenGL and its uses Demonstrate and describe OpenGL’s capabilities and features Enable you to write an interactive, 3-D computer graphics program in OpenGL. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/1.jpg)
An Interactive Introduction to OpenGL Programming
An Interactive Introduction to OpenGL Programming
Ed Angel
Dave Shreiner
Vicki Shreiner
Ed Angel
Dave Shreiner
Vicki Shreiner
![Page 2: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/2.jpg)
WelcomeWelcome
• Today’s Goals and Agenda
– Describe OpenGL and its uses
– Demonstrate and describe OpenGL’s capabilities and features
– Enable you to write an interactive, 3-D computer graphics program in OpenGL
![Page 3: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/3.jpg)
What Is OpenGL, and What Can It Do for Me?What Is OpenGL, and What Can It Do for Me?
• OpenGL is a computer graphics rendering API
– Generate high-quality color images by rendering with geometric and image primitives
– Create interactive applications with 3D graphics
– OpenGL is
• operating system independent
• window system independent
![Page 4: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/4.jpg)
Related APIsRelated APIs
• GLU (OpenGL Utility Library)
– part of OpenGL
– NURBS, tessellators, quadric shapes, etc.
• AGL, GLX, WGL
– glue between OpenGL and windowing systems
• GLUT (OpenGL Utility Toolkit)
– portable windowing API
– not officially part of OpenGL
![Page 5: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/5.jpg)
OpenGL and Related APIs
GLUT
GLU
GL
GLX, AGLor WGL
X, Win32, Mac O/S
software and/or hardware
application program
OpenGL Motifwidget or similar
![Page 6: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/6.jpg)
General Structure of an OpenGL ProgramGeneral Structure of an OpenGL Program
Configure and open a
window Initialize OpenGL’s
state Process user events
Draw an image
![Page 7: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/7.jpg)
An OpenGL ProgramAn OpenGL Program
#include <GL/glut.h>#include "cube.h"
void main( int argc, char *argv[] ){ glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH ); glutCreateWindow( argv[0] );
init();
glutDisplayFunc( display ); glutReshapeFunc( reshape );
glutMainLoop();}
The main part ofthe program.GLUT is used to
open the OpenGLwindow, and handleinput from the user.
![Page 8: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/8.jpg)
An OpenGL Program(cont’d.)An OpenGL Program(cont’d.)
Set up some initial OpenGL state
Handle when theuser resizes the
window
void init( void ){ glClearColor( 0, 0, 0, 1 ); gluLookAt( 2, 2, 2, 0, 0, 0, 0, 1, 0 ); glEnable( GL_DEPTH_TEST );}
void reshape( int width, int height ){ glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 60, (GLfloat) width / height, 1.0, 10.0 ); glMatrixMode( GL_MODELVIEW );}
![Page 9: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/9.jpg)
An OpenGL Program (cont’d.)An OpenGL Program (cont’d.)
void display( void ){ int i, j;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glBegin( GL_QUADS ); for ( i = 0; i < NUM_CUBE_FACES; ++i ) { glColor3fv( faceColor[i] ); for ( j = 0; j < NUM_VERTICES_PER_FACE; ++j ) { glVertex3fv( vertex[face[i][j]] ); } } glEnd();
glFlush();}
Have OpenGLdraw a cubefrom some3D points(vertices)
![Page 10: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/10.jpg)
OpenGL Command Formats
glVertex3fv( glVertex3fv( vv ) )
Number ofNumber ofcomponentscomponents
2 - (x,y) 2 - (x,y) 3 - (x,y,z)3 - (x,y,z)4 - (x,y,z,w)4 - (x,y,z,w)
Data TypeData Typeb - byteb - byteub - unsigned byteub - unsigned bytes - shorts - shortus - unsigned shortus - unsigned shorti - inti - intui - unsigned intui - unsigned intf - floatf - floatd - doubled - double
VectorVector
omit “v” foromit “v” forscalar formscalar form
glVertex2f( x, y )glVertex2f( x, y )
![Page 11: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/11.jpg)
What Is Required For Your ProgramsWhat Is Required For Your Programs
• Headers Files
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
• Libraries
• Enumerated Types
– OpenGL defines numerous types for compatibility
• GLfloat, GLint, GLenum, etc.
![Page 12: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/12.jpg)
GLUT BasicsGLUT Basics
• Application Structure:
– Configure and open window
– Initialize OpenGL state
– Register input callback functions
– Enter event processing loop
![Page 13: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/13.jpg)
GLUT Callback FunctionsGLUT Callback Functions
• Routine to call when something happens
– window resize or redraw
– user input
– animation
• “Register” callbacks with GLUT
glutDisplayFunc( display );
glutIdleFunc( idle );
glutKeyboardFunc( keyboard );
![Page 14: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/14.jpg)
What can OpenGL Draw?What can OpenGL Draw?
• Geometric primitives
– points, lines and polygons
• Image Primitives
– images and bitmaps
– separate pipeline for images and geometry
• linked through texture mapping
• Rendering depends on state
– colors, materials, light sources, etc.
![Page 15: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/15.jpg)
OpenGL Geometric Primitives
• All geometric primitives are specified by vertices
• All geometric primitives are specified by vertices
GL_QUAD_STRIPGL_QUAD_STRIP
GL_POLYGONGL_POLYGON
GL_TRIANGLE_STRIPGL_TRIANGLE_STRIP GL_TRIANGLE_FANGL_TRIANGLE_FAN
GL_POINTSGL_POINTS
GL_LINESGL_LINES
GL_LINE_LOOPGL_LINE_LOOP
GL_LINE_STRIPGL_LINE_STRIP
GL_TRIANGLESGL_TRIANGLES
GL_QUADSGL_QUADS
![Page 16: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/16.jpg)
Specifying Geometric Primitives
• Primitives are specified using
glBegin( glBegin( primType primType ););
glEnd();glEnd();
• primType determines how vertices are combined
glBegin( glBegin( primType primType ););for ( i = 0; i < n; ++i ) { for ( i = 0; i < n; ++i ) { glColor3f( red[i], green[i], blue[i] );glColor3f( red[i], green[i], blue[i] ); glVertex3fv( coords[i] );glVertex3fv( coords[i] );}}glEnd();glEnd();
![Page 17: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/17.jpg)
How OpenGL Works:The Conceptual ModelHow OpenGL Works:The Conceptual Model
Configurehow OpenGLshould draw
stuff
Draw stuff
![Page 18: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/18.jpg)
Controlling OpenGL’s DrawingControlling OpenGL’s Drawing
• Set OpenGL’s rendering state
– State controls how things are drawn
• shading – lighting
• texture maps – line styles (stipples)
• polygon patterns – transparency
![Page 19: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/19.jpg)
The Power of Setting OpenGL StateThe Power of Setting OpenGL State
Appearance is controlled by setting OpenGL’s state.
![Page 20: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/20.jpg)
Setting OpenGL StateSetting OpenGL State
• Three ways to set OpenGL state:
1. Set values to be used for processing vertices
• most common methods of setting state
– glColor() / glIndex()
– glNormal()
– glTexCoord()
• state must be set before calling glVertex()
![Page 21: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/21.jpg)
Setting OpenGL State (cont’d.)Setting OpenGL State (cont’d.)
2.2. Turning on a rendering modeTurning on a rendering mode
glEnable() / glDisable()glEnable() / glDisable()
3.3. Configuring the specifics of a particular rendering Configuring the specifics of a particular rendering modemode
• Each mode has unique commands for setting its values
glMaterialfv()glMaterialfv()
![Page 22: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/22.jpg)
OpenGL and ColorOpenGL and Color
• The OpenGL Color Model
– OpenGL uses the RGB color space• There is also a color-index mode, but we do not discuss it
• Colors are specified as floating-pointnumbers in the range [ 0.0, 1.0 ]
– for example, to set a window’s background color, you would call
glClearColor( 1.0, 0.3, 0.6, 1.0 );
![Page 23: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/23.jpg)
Shapes TutorialShapes Tutorial
![Page 24: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/24.jpg)
TransformationsTransformations
![Page 25: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/25.jpg)
Camera Analogy
• 3D is just like taking a photograph (lots of photographs!)
camera
tripod model
viewingvolume
![Page 26: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/26.jpg)
Camera Analogy and Transformations
• Projection transformations– adjust the lens of the camera
• Viewing transformations– tripod–define position and orientation of the viewing volume
in the world
• Modeling transformations– moving the model
• Viewport transformations– enlarge or reduce the physical photograph
![Page 27: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/27.jpg)
Coordinate Systems and TransformationsCoordinate Systems and Transformations
• Steps in forming an image
1. specify geometry (world coordinates)
2. specify camera (camera coordinates)
3. project (window coordinates)
4. map to viewport (screen coordinates)
• Each step uses transformations
• Every transformation is equivalent to a change in coordinate systems (frames)
![Page 28: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/28.jpg)
Homogeneous Coordinates
– each vertex is a column vector
– w is usually 1.0
– all operations are matrix multiplications
– directions (directed line segments) can be representedwith w = 0.0
w
z
y
x
v
![Page 29: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/29.jpg)
151173
141062
13951
12840
mmmm
mmmm
mmmm
mmmm
M
3D Transformations
• A vertex is transformed by 4 x 4 matrices– all affine operations are matrix multiplications
– all matrices are stored column-major in OpenGL
– matrices are always post-multiplied
– product of matrix and vector is v
M
![Page 30: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/30.jpg)
Specifying TransformationsSpecifying Transformations
• Programmer has two styles of specifying transformations– specify matrices (glLoadMatrix, glMultMatrixglLoadMatrix, glMultMatrix)
– specify operation (glRotate, glOrthoglRotate, glOrtho)
• Programmer does not have to remember the exact matrices– see appendix of the OpenGL Programming Guide
![Page 31: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/31.jpg)
Programming Transformations
• Prior to rendering, view, locate, and orient:
– eye/camera position
– 3D geometry
• Manage the matrices
– including matrix stack
• Combine (composite) transformations
![Page 32: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/32.jpg)
vertex
ModelviewMatrix
ProjectionMatrix
PerspectiveDivision
ViewportTransform
Modelview
Modelview
Projection
object eye
clip normalizeddevice
window
• other calculations here– material color– shade model (flat)– polygon rendering mode– polygon culling– clipping
TransformationPipelineTransformationPipeline
![Page 33: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/33.jpg)
Matrix Operations
• Specify Current Matrix Stack
glMatrixMode(glMatrixMode(GL_MODELVIEWGL_MODELVIEW or or GL_PROJECTIONGL_PROJECTION))
• Other Matrix or Stack Operations
glLoadIdentity() glPushMatrix()glLoadIdentity() glPushMatrix()
glPopMatrix()glPopMatrix()
• Viewport
– usually same as window size
– viewport aspect ratio should be same as projection transformation or resulting image may be distorted
glViewport( glViewport( x, y, width, heightx, y, width, height ) )
• Specify Current Matrix Stack
glMatrixMode(glMatrixMode(GL_MODELVIEWGL_MODELVIEW or or GL_PROJECTIONGL_PROJECTION))
• Other Matrix or Stack Operations
glLoadIdentity() glPushMatrix()glLoadIdentity() glPushMatrix()
glPopMatrix()glPopMatrix()
• Viewport
– usually same as window size
– viewport aspect ratio should be same as projection transformation or resulting image may be distorted
glViewport( glViewport( x, y, width, heightx, y, width, height ) )
![Page 34: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/34.jpg)
Projection Transformation
• Shape of viewing frustum
• Perspective projection
gluPerspective( gluPerspective( fovy, aspect, zNear, zFarfovy, aspect, zNear, zFar ) )
glFrustumglFrustum(( left,left, right,right, bottom,bottom, top,top, zNear,zNear, zFarzFar ))
• Orthographic parallel projection
glOrtho(glOrtho(left,left, right,right, bottom,bottom, top,top, zNear,zNear, zFarzFar))
gluOrtho2D( gluOrtho2D( left, right, bottom, topleft, right, bottom, top ) )
• calls glOrtho with z values near zero
![Page 35: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/35.jpg)
Applying Projection Transformations
• Typical use (orthographic projection)glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(left, right, bottom, top, zNear, zFar);
![Page 36: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/36.jpg)
Viewing Transformations
• Position the camera/eye in the scene– place the tripod down; aim camera
• To “fly through” a scene– change viewing transformation and
redraw scene
gluLookAt( eyex, eyey, eyez, aimx, aimy, aimz, upx, upy, upz )
– up vector determines unique orientation
– careful of degenerate positions
tripod
![Page 37: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/37.jpg)
Projection TutorialProjection Tutorial
![Page 38: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/38.jpg)
Modeling Transformations
• Move object
glTranslate{fd}( glTranslate{fd}( x, y, zx, y, z ) )
• Rotate object around arbitrary axis
glRotate{fd}( glRotate{fd}( angle, x, y, zangle, x, y, z ) )
– angle is in degrees
• Dilate (stretch or shrink) or mirror object
glScale{fd}( glScale{fd}( x, y, zx, y, z ) )
zyx
![Page 39: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/39.jpg)
Transformation TutorialTransformation Tutorial
![Page 40: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/40.jpg)
Connection: Viewing and Modeling
• Moving camera is equivalent to moving every object in the world towards a stationary camera
• Viewing transformations are equivalent to several modeling transformations
– gluLookAt() has its own command
– can make your own polar view or pilot view
![Page 41: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/41.jpg)
Compositing Modeling Transformations
• Problem: hierarchical objects
– one position depends upon a previous position
– robot arm or hand; sub-assemblies
• Solution: moving local coordinate system
– modeling transformations move coordinate system
– post-multiply column-major matrices
– OpenGL post-multiplies matrices
![Page 42: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/42.jpg)
Compositing Modeling Transformations• Problem: objects move relative to absolute world origin
– my object rotates around the wrong origin
• make it spin around its center or something else
• Solution: fixed coordinate system
– modeling transformations move objects around fixed coordinate system
– pre-multiply column-major matrices
– OpenGL post-multiplies matrices
– must reverse order of operations to achieve desired effect
![Page 43: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/43.jpg)
Additional Clipping Planes
• At least 6 more clipping planes available
• Good for cross-sections
• Modelview matrix moves clipping plane
• clipped
glEnable( GL_CLIP_PLANEi )
glClipPlane( GL_CLIP_PLANEi, GLdouble* coeff )
0 DCzByAx
![Page 44: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/44.jpg)
Animation and Depth BufferingAnimation and Depth Buffering
![Page 45: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/45.jpg)
DoubleBuffering
12
48
16
12
48
16FrontBuffer
BackBuffer
Display
![Page 46: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/46.jpg)
Animation Using Double Buffering
Request a double buffered color buffer
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
Clear color buffer
glClear( GL_COLOR_BUFFER_BIT );
Render scene
Request swap of front and back buffers
glutSwapBuffers();
• Repeat steps 2 - 4 for animation
Request a double buffered color buffer
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
Clear color buffer
glClear( GL_COLOR_BUFFER_BIT );
Render scene
Request swap of front and back buffers
glutSwapBuffers();
• Repeat steps 2 - 4 for animation
![Page 47: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/47.jpg)
Depth Buffering andHidden Surface Removal
12
48
16
12
48
16ColorBuffer
DepthBuffer
Display
![Page 48: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/48.jpg)
Depth Buffering Using OpenGL Request a depth buffer
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
Enable depth bufferingglEnable( GL_DEPTH_TEST );
Clear color and depth buffersglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
Render scene Swap color buffers
Request a depth bufferglutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
Enable depth bufferingglEnable( GL_DEPTH_TEST );
Clear color and depth buffersglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
Render scene Swap color buffers
![Page 49: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/49.jpg)
LightingLighting
![Page 50: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/50.jpg)
Lighting PrinciplesLighting Principles
• Lighting simulates how objects reflect light
– material composition of object
– light’s color and position
– global lighting parameters
• ambient light
• two sided lighting
– available in both color indexand RGBA mode
![Page 51: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/51.jpg)
How OpenGL Simulates LightsHow OpenGL Simulates Lights
• Phong lighting model
– Computed at vertices
• Lighting contributors
– Surface material properties
– Light properties
– Lighting model properties
![Page 52: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/52.jpg)
SurfaceNormalsSurfaceNormals
• Normals define how a surface reflects light
glNormal3f( x, y, z )
– Current normal is used to compute vertex’s color
– Use unit normals for proper lighting
• scaling affects a normal’s length
glEnable( GL_NORMALIZE )or
glEnable( GL_RESCALE_NORMAL )
![Page 53: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/53.jpg)
Material PropertiesMaterial Properties
• Define the surface properties of a primitive
glMaterialfv( face, property, value );
– separate materials for front and back
GL_DIFFUSE Base color
GL_SPECULAR Highlight Color
GL_AMBIENT Low-light Color
GL_EMISSION Glow Color
GL_SHININESS Surface Smoothness
![Page 54: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/54.jpg)
Light PropertiesLight Properties
glLightfv( light, property, value );
– light specifies which light
• multiple lights, starting with GL_LIGHT0
glGetIntegerv( GL_MAX_LIGHTS, &n );
– properties• colors
• position and type
• attenuation
![Page 55: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/55.jpg)
Light Sources (cont'd.)
• Light color properties
– GL_AMBIENT
– GL_DIFFUSE
– GL_SPECULAR
• Light color properties
– GL_AMBIENT
– GL_DIFFUSE
– GL_SPECULAR
![Page 56: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/56.jpg)
Types of LightsTypes of Lights
• OpenGL supports two types of Lights
– Local (Point) light sources
– Infinite (Directional) light sources
• Type of light controlled by w coordinate
wz
wy
wxw
zyxw
at positioned Light Local
along directed LightInfinite
0
0
![Page 57: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/57.jpg)
Turning on the LightsTurning on the Lights
• Flip each light’s switch
glEnable( GL_LIGHTn );
• Turn on the power
glEnable( GL_LIGHTING );
![Page 58: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/58.jpg)
Light Material TutorialLight Material Tutorial
![Page 59: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/59.jpg)
Controlling a Light’s PositionControlling a Light’s Position
• Modelview matrix affects a light’s position
– Different effects based on when position is specified
• eye coordinates
• world coordinates
• model coordinates
– Push and pop matrices to uniquely control a light’s position
![Page 60: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/60.jpg)
Light Position TutorialLight Position Tutorial
![Page 61: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/61.jpg)
Tips for Better LightingTips for Better Lighting
• Recall lighting computed only at vertices
– model tessellation heavily affects lighting results
• better results but more geometry to process
• Use a single infinite light for fastest lighting
– minimal computation per vertex
![Page 62: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/62.jpg)
Imaging and Raster PrimitivesImaging and Raster Primitives
![Page 63: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/63.jpg)
Pixel-based primitivesPixel-based primitives
• Bitmaps
– 2D array of bit masks for pixels• update pixel color based on current color
• Images
– 2D array of pixel color information• complete color information for each pixel
• OpenGL does not understand image formats
![Page 64: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/64.jpg)
FrameBuffer
Rasterization(including
Pixel Zoom)
Per FragmentOperations
TextureMemory
Pixel-TransferOperations
(and Pixel Map)CPU
PixelStorageModes
glReadPixels(), glCopyPixels()
glBitmap(), glDrawPixels()
glCopyTex*Image();
Pixel PipelinePixel Pipeline
• Programmable pixel storage and transfer operations
![Page 65: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/65.jpg)
Positioning Image PrimitivesPositioning Image Primitives
glRasterPos3f( x, y, z )
– raster position transformed like geometry
– discarded if raster positionis outside of viewport
• may need to fine tuneviewport for desiredresults
Raster Position
![Page 66: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/66.jpg)
Texture MappingPart 1Texture MappingPart 1
![Page 67: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/67.jpg)
Texture MappingTexture Mapping
s
t
x
y
z
image
geometry screen
![Page 68: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/68.jpg)
Texture Mapping and the OpenGL PipelineTexture Mapping and the OpenGL Pipeline
geometry pipelinevertices
pixel pipelineimage
rasterizer
• Images and geometry flow through separate pipelines that join at the rasterizer
– “complex” textures do not affect geometric complexity
![Page 69: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/69.jpg)
Texture ExampleTexture Example
• The texture (below) is a 256 x 256 image that has been mapped to a rectangular polygon which is viewed in perspective
![Page 70: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/70.jpg)
Applying Textures IApplying Textures I
• Three steps to applying a texture
1. specify the texture• read or generate image
• assign to texture
• enable texturing
2. assign texture coordinates to vertices
3. specify texture parameters• wrapping, filtering
![Page 71: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/71.jpg)
Texture Objects
• Have OpenGL store your images– one image per texture object
– may be shared by several graphics contexts
• Generate texture names
glGenTextures( n, *texIds );
![Page 72: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/72.jpg)
Texture Objects (cont'd.)Texture Objects (cont'd.)
• Create texture objects with texture data and state
glBindTexture( target, id );
• Bind textures before using
glBindTexture( target, id );
![Page 73: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/73.jpg)
• Define a texture image from an array of texels in CPU memory
glTexImage2D( target, level, components, w, h, border, format, type, *texels );
– dimensions of image must be powers of 2
• Texel colors are processed by pixel pipeline
– pixel scales, biases and lookups can bedone
Specify TextureImageSpecify TextureImage
![Page 74: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/74.jpg)
Converting A Texture Image
• If dimensions of image are not power of 2
gluScaleImage( format, w_in, h_in, type_in, *data_in, w_out, h_out,
type_out, *data_out );
– *_in is for source image
– *_out is for destination image
• Image interpolated and filtered during scaling
![Page 75: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/75.jpg)
• Based on parametric texture coordinates
• glTexCoord*() specified at each vertex
s
t1, 1
0, 1
0, 0 1, 0
(s, t) = (0.2, 0.8)
(0.4, 0.2)
(0.8, 0.4)
A
B C
a
bc
Texture Space Object Space
Mapping aTextureMapping aTexture
![Page 76: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/76.jpg)
Generating Texture Coordinates
• Automatically generate texture coords
glTexGen{ifd}[v]()
• specify a plane
– generate texture coordinates based upon distance from plane
• generation modes
– GL_OBJECT_LINEAR
– GL_EYE_LINEAR
– GL_SPHERE_MAP
0 DCzByAx
![Page 77: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/77.jpg)
Tutorial: TextureTutorial: Texture
![Page 78: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/78.jpg)
Texture MappingPart 2Texture MappingPart 2
![Page 79: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/79.jpg)
Applying Textures II
– specify textures in texture objects
– set texture filter
– set texture function
– set texture wrap mode
– set optional perspective correction hint
– bind texture object
– enable texturing
– supply texture coordinates for vertex
• coordinates can also be generated
– specify textures in texture objects
– set texture filter
– set texture function
– set texture wrap mode
– set optional perspective correction hint
– bind texture object
– enable texturing
– supply texture coordinates for vertex
• coordinates can also be generated
![Page 80: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/80.jpg)
• Filter Modes
– minification or magnification
– special mipmap minification filters
• Wrap Modes
– clamping or repeating
• Texture Functions
– how to mix primitive’s color with texture’s color
• blend, modulate or replace texels
Texture Application Methods
![Page 81: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/81.jpg)
Filter Modes
Texture Polygon
Magnification Minification
PolygonTexture
Example:
glTexParameteri( glTexParameteri( target, type, modetarget, type, mode ); );
![Page 82: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/82.jpg)
Mipmapped Textures
• Mipmap allows for prefiltered texture maps of decreasing resolutions
• Lessens interpolation errors for smaller textured objects
• Declare mipmap level during texture definition
glTexImage*D( glTexImage*D( GL_TEXTURE_*D, level, …GL_TEXTURE_*D, level, … ) )
• GLU mipmap builder routines
gluBuild*DMipmaps( … )gluBuild*DMipmaps( … )
• OpenGL 1.2 introduces advanced LOD controls
![Page 83: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/83.jpg)
Wrapping Mode
• Example:
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP )
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT )
texture
s
t
GL_CLAMPwrapping
GL_REPEATwrapping
![Page 84: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/84.jpg)
Texture Functions
• Controls how texture is appliedglTexEnv{fi}[v]( GL_TEXTURE_ENV, prop, param )
• GL_TEXTURE_ENV_MODE modes
– GL_MODULATE
– GL_BLEND
– GL_REPLACE
• Set blend color with GL_TEXTURE_ENV_COLOR
![Page 85: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/85.jpg)
Advanced OpenGL TopicsAdvanced OpenGL Topics
![Page 86: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/86.jpg)
Immediate Mode versus Display Listed Rendering
• Immediate Mode Graphics
– Primitives are sent to pipeline and display right away
– No memory of graphical entities
• Display Listed Graphics
– Primitives placed in display lists
– Display lists kept on graphics server
– Can be redisplayed with different state
– Can be shared among OpenGL graphics contexts
![Page 87: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/87.jpg)
Immediate Mode versus Display Lists
Immediate Mode
Display Listed
DisplayList
PolynomialEvaluator
Per VertexOperations &
PrimitiveAssembly
RasterizationPer Fragment
Operations
TextureMemory
CPU
PixelOperations
FrameBuffer
![Page 88: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/88.jpg)
Display Lists
• Creating a display listGLuint id;void init( void ){ id = glGenLists( 1 ); glNewList( id, GL_COMPILE ); /* other OpenGL routines */ glEndList();}
• Call a created listvoid display( void ){ glCallList( id );}
![Page 89: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/89.jpg)
Display Lists
• Not all OpenGL routines can be stored in display lists
• State changes persist, even after a display list is finished
• Display lists can call other display lists
• Display lists are not editable, but you can fake it
– make a list (A) which calls other lists (B, C, and D)
– delete and replace B, C, and D, as needed
![Page 90: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/90.jpg)
Display Lists and HierarchyDisplay Lists and Hierarchy
• Consider model of a car
– Create display list for chassis
– Create display list for wheelglNewList( CAR, GL_COMPILE );
glCallList( CHASSIS );glTranslatef( … );glCallList( WHEEL );glTranslatef( … );glCallList( WHEEL );
…glEndList();
![Page 91: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/91.jpg)
Advanced Primitives
• Vertex Arrays
• Bernstein Polynomial Evaluators
– basis for GLU NURBS
• NURBS (Non-Uniform Rational B-Splines)
• GLU Quadric Objects
– sphere
– cylinder (or cone)
– disk (circle)
• Vertex Arrays
• Bernstein Polynomial Evaluators
– basis for GLU NURBS
• NURBS (Non-Uniform Rational B-Splines)
• GLU Quadric Objects
– sphere
– cylinder (or cone)
– disk (circle)
![Page 92: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/92.jpg)
Alpha: the 4th Color ComponentAlpha: the 4th Color Component
• Measure of Opacity
– simulate translucent objects
• glass, water, etc.
– composite images
– antialiasing
– ignored if blending is not enabled
glEnable( GL_BLEND )
![Page 93: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/93.jpg)
BlendingBlending
• Combine fragments with pixel values that are already in the framebuffer
glBlendFunc( src, dst )
FramebufferFramebufferPixelPixel((dstdst))
BlendingEquation
BlendingEquation
FragmentFragment((srcsrc))
BlendedBlendedPixelPixel
pfr CdstCsrcC
![Page 94: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/94.jpg)
FogFog
glFog{if}( property, value )
• Depth Cueing
– Specify a range for a linear fog ramp• GL_FOG_LINEAR
• Environmental effects
– Simulate more realistic fog• GL_FOG_EXP
• GL_FOG_EXP2
![Page 95: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/95.jpg)
Multi-pass RenderingMulti-pass Rendering
• Blending allows results from multiple drawing passes to be combined together
– enables more complex rendering algorithms
Example of bump-mappingdone with a multi-pass
OpenGL algorithm
![Page 96: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/96.jpg)
AntialiasingAntialiasing
• Removing the Jaggies
glEnable( mode )• GL_POINT_SMOOTH
• GL_LINE_SMOOTH
• GL_POLYGON_SMOOTH
– alpha value computed by computingsub-pixel coverage
– available in both RGBA and colormap modes
![Page 97: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/97.jpg)
Accumulation BufferAccumulation Buffer
• Problems of compositing into color buffers– limited color resolution
• clamping
• loss of accuracy
– Accumulation buffer acts as a “floating point” color buffer
• accumulate into accumulation buffer
• transfer results to frame buffer
![Page 98: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/98.jpg)
Accumulation Buffer ApplicationsAccumulation Buffer Applications
• Compositing
• Full Scene Antialiasing
• Depth of Field
• Filtering
• Motion Blur
![Page 99: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/99.jpg)
Stencil BufferStencil Buffer
• Used to control drawing based on values in the stencil buffer
– Fragments that fail the stencil test are not drawn
– Example: create a mask in stencil buffer and draw only objects not in mask area
![Page 100: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/100.jpg)
Fog TutorialFog Tutorial
![Page 101: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/101.jpg)
Getting to the FramebufferGetting to the Framebuffer
BlendingBlendingDepthTest
DepthTest DitheringDithering Logical
Operations
LogicalOperations
ScissorTest
ScissorTest
StencilTest
StencilTest
AlphaTest
AlphaTest
Fra
gmen
t
Fra
meb
uffe
r
![Page 102: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/102.jpg)
Alpha TestAlpha Test
• Reject pixels based on their alpha value
glAlphaFunc( func, value )
glEnable( GL_ALPHA_TEST )
– use alpha as a mask in textures
![Page 103: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/103.jpg)
GPUs and GLSLGPUs and GLSL
• Over the past few years, graphical processing units (GPUs) have become more powerful and now are programmable
• Support first through OpenGL extensions and OpenGL Shading Language (GLSL)
• Incorporated in OpenGL 2.0
![Page 104: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/104.jpg)
OpenGL Pipeline RevisitedOpenGL Pipeline Revisited
GeometryProcessingGeometryProcessing RasterizationRasterization
FragmentProcessingFragmentProcessing
FrameBufferFrameBuffer
CPUCPUTextureMemoryTextureMemory
texelstexels
verticesvertices verticesvertices fragmentsfragments
pixelspixels
![Page 105: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/105.jpg)
Geometry ProcessingGeometry Processing
• Coordinate Transformations
• Primitive Assembly
• Clipping
• Per-vertex lighting
• Programmable through a vertex program or vertex shader
![Page 106: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/106.jpg)
RasterizerRasterizer
• Outputs fragments (“potential pixels”) that are interior to primitives
• Interpolates colors, depth, texture coordinates, and other per vertex variables to obtain values for each fragment
• Not programmable
![Page 107: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/107.jpg)
Fragment ProcessingFragment Processing
• Assigns color to each fragment and updates frame buffer
• Handles hidden surface removal, texture mapping, and blending
• Programmable through fragment program or fragment shader
![Page 108: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/108.jpg)
GLSLGLSL
• OpenGL Shading Language
• C like language for writing both vertex and fragment shaders
• Adds matrix and vector data types + overloading of operators
• OpenGL state variables available to shaders
• Variables can be passed among shaders and applications
![Page 109: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/109.jpg)
Vertex Shader ApplicationsVertex Shader Applications
• General Vertex Lighting
• Off loading CPU
• Dynamic Meshes
• Morphing
• Additional Application Specific Vertex Attributes
![Page 110: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/110.jpg)
Vertex Shader Execution Vertex Shader Execution
![Page 111: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/111.jpg)
Fragment Shader ApplicationsFragment Shader Applications
• Per Fragment Lighting
• Bump Maps
• Environment Maps
• Texture Manipulation
• Shadow Maps
![Page 112: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/112.jpg)
Fragment Shader ExecutionFragment Shader Execution
![Page 113: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/113.jpg)
Linking with ApplicationLinking with Application
• In OpenGL application, we must:
– Read shaders
– Compile shaders
– Define variables
– Link everything together
• OpenGL 2.0 contains a set of functions for each of these steps
![Page 114: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/114.jpg)
Summary / Q & ASummary / Q & A
Ed Angel
Dave Shreiner
Vicki Shreiner
![Page 115: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/115.jpg)
On-Line ResourcesOn-Line Resources
– http://www.opengl.org
• start here; up to date specification and lots of sample code
– news:comp.graphics.api.opengl
– http://www.sgi.com/software/opengl
– http://www.mesa3d.org/
• Brian Paul’s Mesa 3D
– http://www.cs.utah.edu/~narobins/opengl.html
• very special thanks to Nate Robins for the OpenGL Tutors
• source code for tutors available here!
![Page 116: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/116.jpg)
Books
• OpenGL Programming Guide, 4th Edition
• OpenGL Reference Manual, 4th Edition
• Interactive Computer Graphics: A top-down approach with OpenGL, 4rd Edition
• OpenGL Programming for the X Window System
– includes many GLUT examples
![Page 117: An Interactive Introduction to OpenGL Programming](https://reader036.vdocuments.us/reader036/viewer/2022062804/56814bbb550346895db88df8/html5/thumbnails/117.jpg)
Thanks for ComingThanks for Coming
• Questions and Answers
Ed Angel [email protected]
Dave Shreiner [email protected]
Vicki Shreiner [email protected]