Computer Science Is No More About Computers Than Astronomy Is About Telescopes
Computer Science Is No More About Computers Than Astronomy Is About Telescopes
OpenGL
Application
Frame Buffer
Display
Event Loop
• OpenGL programs often run in an event loop:
– Start the program
– Run some initialization code
– Run an infinite loop and wait for events such as
• Key press
• Mouse move, click
• Reshape window
• Expose event
OpenGL Command Syntax (1)
• OpenGL commands start with “gl”
• OpenGL constants start with “GL_”
• Some commands end in a number and one, two or three letters
at the end (indicating number and type of arguments)
• A Number indicates number of arguments
• Characters indicate type of argument
OpenGL Command Syntax (2)
– `f' float
– `d' double float
– `s' signed short integer
– `i' signed integer
– `b' character
– `ub' unsigned character
– `us' unsigned short integer
– `ui' unsigned integer
OpenGL Command Syntax (3)
• “v” at the end of the name indicates a vector format.
Examples: glColor*()
• glColor3b, glColor3d, glColor3f, glColor3i, glColor3s,
glColor3ub, glColor3ui, glColor3us, glColor4b, glColor4d,
glColor4f, glColor4i, glColor4s, glColor4ub, glColor4ui,
glColor4us, glColor3bv, glColor3dv, glColor3fv,
glColor3iv, glColor3sv, glColor3ubv, glColor3uiv,
glColor3usv, glColor4bv, glColor4dv, glColor4fv,
glColor4iv, glColor4sv, glColor4ubv, glColor4uiv,
glColor4usv
OpenGL Primitives
• GL_POINTS
• GL_LINES
• GL_LINE_STRIP
• GL_LINE_LOOP
• GL_TRIANGLES
• GL_TRIANGLE_STRIP
• GL_TRIANGLE_FAN
• GL_QUADS
• GL_QUAD_STRIP
• GL_POLYGON
Scene Graph
Ground
T1
Body
T2 T3 T4
N = P0 − Pref
• View-up vector V
– N and V are specified in the world coordinates
Viewing-Coordinate Reference Frame
• The camera orientation is determined by the uvn reference
frame
N
n= = (nx , n y , nz )
N
V ×n
u= = (u x , u y , u z )
V u
v
n
v = n × u = (v x , v y , v z )
World-to-Viewing Transformation
u x uy uz 0 1 0 0 − x0
v vy vz 0 0 1 0 − y0
R= x T=
nx ny nz 0 0 0 1 − z0
0 0 0 1 0 0 0 1
u x uy uz − u ⋅ P0
v vy vz − v ⋅ P0
M wc ,vc = R ⋅T = x
n x ny nz − n ⋅ P0
0 0 0 1
Perspective-Projection View Volume
• Viewing frustum
– Why do we need near and far clipping plane ?
Normalizing Transformation
• Transform an arbitrary perspective-projection view volume
into the canonical view volume