OpenGL review session
-
Introduction – why OpenGL
-
What does OpenGL do
-
Draw stuff "onscreen", in 2D and 3D
-
What doesn't it do
-
Windows, menus, define what "onscreen" is, share the display,
input devices
-
GLUT as windowing interface
-
Makes up for most of the things in the "What doesn't it do"
section
-
OpenGL + GLUT + {insert your windowing system here} make a pretty
complete combination.
-
OGL/GLUT app should be portable across the various Unix platforms and
Win32
-
GLUT overview
-
Mostly one-time initialization
See sample code in /usr/class/cs248/assignments/assigment3/example/simple
// GLUT Window Initialization:
glutInit (&argc, argv);
glutInitWindowSize (g_Width,
g_Height);
glutInitDisplayMode ( GLUT_RGB |
GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow ("CS248 GLUT
example");
-
Callback model (like xsupport)
// Register callbacks:
glutDisplayFunc (display);
glutXXXXXXXFunc (callbackName);
...
glutMainLoop();
-
More info:
-
OpenGL overview
-
Function names like glXXX
-
Data types like 2i, 3f, fv
-
glBegin, glEnd to specify polygons
-
glVertex, glNormal to specify vertices inside polygons
-
state management
-
many functions apply to current state
have lots of other functions to select/modify current state
-
Rendering in OpenGL – basic 2D
-
How to get a basic 2D drawing onscreen
-
Clearing screen – glClearColor, glClear
-
Viewport – glViewport
-
Orthographic projection – glOrtho
-
Specifying colors – glColor*
-
Specifying vertices – glVertex*
-
Making polygons out of vertices (glBegin/glEnd)
-
Rendering in OpenGL – 3D
Overview of pipeline
Viewing
Transformation, 2 matrices
Backface culling
Clipping
Depth test
Lighting
Diffuse, specular, ambient
Multiple lights
Depends on normal vectors -- glNormal
Shading
Based on light position, materials, normals
Calculated for each vertex, interpolated to fill polygon (Gouraud shading)
Transformation model
glLoadIdentity
glOrtho, gluPerspective
Common modelview transformations
for model:
glRotate, glTranslate, glScale
General transformations: glMultMatrix
Rendering primitives
Z buffer (hidden surface removal)
Texture mapping
Enable texturing – glEnable (GL_TEXTURE_2D)
Bind texture to context -- glBindTexture
Build mipmaps – gluBuild2DMipmaps
Set filtering options – glTexParameteri
Specifying texture coordinates
Automatically -- glTexGen
-
Performance considerations
Triangle strips – good
Vertex arrays – often good
Display lists – sometimes good
Texture mapping
Mipmaps
Hardware vs. software
-
Gotchas
Lighting
Clipping – esp. near/far planes
Avoid the dreaded �black screen�
make small reversible changes
to your code until you get a feel for what does what
-
More hints
Use man pages on SGI's
man -k concept | grep ^gl
last year's review session notes