Beruflich Dokumente
Kultur Dokumente
By Nick Gnedin
• What is OpenGL?
• Object Modeling
• Lighting and Shading
• Computer Viewing
• Rendering
• Texture Mapping
• Homogeneous Coordinates
3
What Is OpenGL?
The Programmer’s Interface
5
SGI and GL
6
OpenGL
7
OpenGL Evolution
8
OpenGL Libraries
application program
OpenGL Motif
widget or similar GLUT
GLX, AGL
or WGL GLU
10
Windowing with OpenGL
11
API Contents
12
OpenGL State
13
OpenGL function format
function name
glVertex3f(x,y,z)
glVertex3fv(p)
p is a pointer to an array
14
OpenGL #defines
15
Object Modeling
OpenGL Primitives
GL_POINTS GL_POLYGON
GL_LINES GL_LINE_STRIP
GL_LINE_LOOP
GL_TRIANGLES
GL_QUAD_STRIP
GL_TRIANGLE_STRIP GL_TRIANGLE_FAN
17
Example: Drawing an Arc
18
The Line Strip Primitive
void drawArc(float x, float y, float r,
float t0, float sweep)
{
float t, dt; /* angle */
int n = 30; /* # of segments */
int i;
t = t0 * PI/180.0; /* radians */
dt = sweep * PI/(180*n); /* increment */
glBegin(GL_LINE_STRIP);
for(i=0; i<=n; i++, t += dt)
glVertex2f(x + r*cos(t), y + r*sin(t));
glEnd();
}
19
Polygon Issues
21
RGB color
22
Lighting and Shading
Lighting Principles
24
Types of Lights
25
Spotlights
• Have:
- Direction (vector)
- Cutoff (cone opening angle)
- Attenuation with angle
−θ φ θ
26
Moving Light Sources
27
Steps in OpenGL shading
28
Normals
p2
Note that right-hand rule
determines outward face
p p1
p0
29
Polygonal Shading
31
Smooth Shading
32
Mesh Shading
33
Gouraud and Phong Shading
• Gouraud Shading
- Find average normal at each vertex (vertex normals)
- Apply Phong model at each vertex
- Interpolate vertex shades across each polygon
• Phong shading
- Find vertex normals
- Interpolate vertex normals across edges
- Find shades along edges
- Interpolate edge shades across polygons
34
Comparison
35
Front and Back Faces
- Diffuse
- Ambient
- Specular
- Shininess
- Emission
37
Emissive Term
38
Transparency
39
Transparency
40
Computer Viewing
Camera Analogy
viewing
volume
camera
model
tripod
42
OpenGL Orthogonal
(Parallel) Projection
43
OpenGL Perspective
Projection
44
Projections
Orthogonal/Parallel Perspective
45
Clipping
46
Rendering
Rendering Process
48
Hidden-Surface Removal
49
Rasterization
50
Double Buffering
1 1
2 2
4 4
Front 8 8 Back
16 16
Buffer Buffer
Display
51
Immediate and Retained Modes
53
Display Lists and State
55
Antialiasing
56
Texture Mapping
The Limits of Geometric
Modeling
• Although graphics cards can render over
10 million polygons per second, that
number is insufficient for many phenomena
- Clouds
- Grass
- Terrain
- Skin
58
Modeling an Orange
60
Three Types of Mapping
• Texture Mapping
- Uses images to fill inside of polygons
• Environmental (reflection mapping)
- Uses a picture of the environment for texture
maps
- Allows simulation of highly specular surfaces
• Bump mapping
- Emulates altering normal vectors during the
rendering process
61
Texture Mapping
63
Bump Mapping
64
Where does mapping take
place?
• Mapping techniques are implemented at the end
of the rendering pipeline
- Very efficient because few polygons pass down
the geometric pipeline
65
Is it simple?
2D image
3D surface
66
Texture Mapping
parametric coordinates
texture coordinates
screen coordinates
world coordinates
67
Basic Strategy
68
Texture Mapping
z x
geometry screen
t
image
s 69
Mapping a Texture
c (0.4, 0.2)
b
B C
0, 0 1, 0 s (0.8, 0.4)
70
Homogeneous Coordinates
A Single Representation
75
Representing second
basis in terms of first
Each of the basis vectors, u1,u2, u3, are vectors
that can be represented in terms of the first
basis
v
u1 = γ11v1+γ12v2+γ13v3
u2 = γ21v1+γ22v2+γ23v3
u3 = γ31v1+γ32v2+γ33v3
76
Matrix Form
78
Representing One Frame in
Terms of the Other
Extending what we did with change of bases
u1 = γ11v1+γ12v2+γ13v3
u2 = γ21v1+γ22v2+γ23v3
u3 = γ31v1+γ32v2+γ33v3
Q0 = γ41v1+γ42v2+γ43v3 +P0
defining a 4 x 4 matrix
γ11 γ12 γ13 0
γ 21 γ 22 γ 23 0
M=
γ 31 γ 32 γ 33 0
γ 41 γ 42 γ 43 1
79
Working with Representations
x’ = x cos θ – y sin θ
y’ = x sin θ + y cos θ
x = r cos φ
y = r sin φ
86
Rotation about the z-axis
- or in homogeneous coordinates
p’=Rz(θ)p
87
Rotation Matrix
cos θ − sin θ 0 0
R = Rz(θ) = sin θ cos θ 0 0
0 0 1 0
0 0 0 1
88
Scaling
Expand or contract along each axis (fixed point of origin)
x’=sxx
y’=syy
z’=szz
p’=Sp
sx 0 0 0
0 sy 0 0
S = S(sx, sy, sz) =
0 0 sz 0
0 0 0 1
89
Reflection
sx = -1 sy = 1 original
sx = -1 sy = -1 sx = 1 sy = -1
90
Concatenation
93
Shear
94
Shear Matrix
x’ = x + y cot θ
y’ = y
z’ = z
1 cot θ 0 0
0 1 0 0
H(θ) =
0 0 1 0
0 0 0 1
95
Quaternions
96