Title: OpenGL and Parametric Curves
1OpenGL and Parametric Curves
- Advanced Multimedia Technology Computer Graphics
- Yung-Yu Chuang
- 2005/12/21
with slides by Brian Curless, Zoran Popovic,
Robin Chen and Doug James
2Review of graphics pipeline
Transformation
3Review of graphics pipeline
Projection clipping
4Review of graphics pipeline
5Review of graphics pipeline
6Hierarchical modeling a robot arm
7First implementation
8Better implementation
9OpenGL implementation
10Hierarchical modeling
11Implementation
12Human with hands
13Better implementation
14OpenGL implementation
15OpenGL
- A low-level OS-independent graphics API for 2D
and 3D interactive graphics. - Initiated by SGI (called GL at early time)
- Implementation, for Windows, hardware vendors
provide suitable drivers for their own products
for Linux, we have Mesa.
16Helper libraries
- OpenGL does not provide OS-dependent functions
such as windowing and input - GL core graphics functions
- GLU graphics utilities in top of GL
- GLUT input and windowing functions
17How does it work?
- From the programmers view
- Specify geometric properties of the objects
- Describe material properties
- Define viewing
- Define camera and object transformations
- OpenGL is a state machine
- States color, material properties, line width,
current viewing - States are applied to subsequent drawing commands
- Input description of geometric objects
- Output shaded pixels
18How does it work
- From the implementers perspective
- Graphics pipeline
Primitives material properties
Rotate Translate Scale
Is it Visible?
3D to 2D
Scan conversion Visibility determination
Display
19Primitives drawing a polygon
- // put GL into polygon drawing mode
- glBegin(GL_POLYGON)
- // define vertices
- glVertex2f(x0, y0)
- glVertex2f(x1, y1)
- glVertex2f(x2, y2)
- glEnd()
Code available at http//www.xmission.com/nate/tu
tors.html
20Primitives
Hardware may be more efficient on triangles
stripes require less data
21Polygon restrictions
- In OpenGL, polygons must be simple and convex
not simple
not convex
22Attributes
- Part of the state of the graphics pipeline
- Set before primitives are drawn.
- Remain in effect!
- Example
- Color, including transparency
- Reflection properties
- Shading properties
23Primitives material properties
- glColor3f(r,g,b)
- All subsequent primitives will use this color.
Colors are not attached to objects. The above
command only changes the system states. - OpenGL uses red, green and blue color model. Each
components are ranged within 0 and 1.
24Primitives material properties
25Simple transformations
- Rotate by a given angle (in degrees) about ray
from origin through (x,y,z) - glRotatefd(angle, x, y, z)
- Translate by a given x, y, z values
- glTranslatefd(x, y, z)
- Scale with a factor in the x, y, and z directions
- glScalefd(x, y, z)
- glPushMatrix() glPopMatrix()
26Orthographic projection
- glOrtho(left, right, bottom, top, near, far)
27Camera transformations
- gluLookAt(eyex, eyey, eyez, cx, cy, cz, upx, upy,
upz)
28Example drawing a box
29Example drawing a shaded polygon
30Initializing attributes
31Callback functions
- Handle events, Idle, Keyboard, Mouse, Menu,
Motion, Reshape - The display callback is installed by
glutDisplayFunc()
32Actual drawing function
33Results
glShadeModel(GL_FLAT)
glShadeModel(GL_SMOOTH)
34Depth buffer in OpenGL
- glutInitDisplayMode(GLUT_DEPTH)
- glEnable(GL_DEPTH_TEST)
- glClear(GL_DEPTH_BUFFER_BIT)
35Double buffering
- Flicker if drawing overlaps screen refresh
- Solution use two frame buffers
- Draw into one buffer
- Swap and display, while drawing other buffer
- glutInitDisplayMode(GLUT_SINGLE)
- glutInitDisplayMode(GLUT_DOUBLE)
- glutSwapBuffers()
36Example rotate a color cube
- Step 1 define the vertices
37Example rotate a color cube
- Step 2 enable depth testing and double buffering
38Example rotate a color cube
- Step 3 create window and set callbacks
39Example rotate a color cube
- Step 4 reshape callback, enclose cube, preserve
aspect ratio
40Example rotate a color cube
- Step 5 display callback, clear, rotate, draw,
flush, swap
41Example rotate a color cube
- Step 6 draw cube by drawing faces, orientation
consistency
42Example rotate a color cube
43Example rotate a color cube
- Step 8 animation, set idle callback spinCube()
44Example rotate a color cube
- Step 9 change axis of rotation using mouse
callback
45Example rotate a color cube
- Step 10 toggle rotation or exit using keyboard
callback
46Mathematical curve representation
47Parametric polynomial curves
48Cubic curves
N too small ? less flexibility in controlling the
shape of the curve N too
large ? often introduce unwanted wiggles
49Compact representation
50Constrain the cubics
Hermite defined by two endpoints and two
endpoint tangent vectors Bezier
defined by two endpoints and two other points
that control the endpoint tangent
vectors Spline defined by four control points
51Hermite curves
52Computing Hermite basis matrix
53Computing Hermite basis matrix
54Computing a point
55Blending functions
56Bezier curves
57Bezier basis matrix
58Bezier basis matrix
59Bezier blending function
60Alternative (de Casteljaus algorithm)
61Finding Q(u)
62Bezier curve
- each is between 0 and 1
- sum of all four is exactly 1
Curve lies within the convex Hull of its control
points
63Displaying Bezier curves
64Testing for flatness
65What do we want for a curve?
- Local control
- Interpolation
- Continuity
66Local control
- One problem with Bezier curve is that every
control points affect every point on the curve
(except for endpoints). Moving a single control
point affects the whole curve.
- Wed like to have local control, that is, have
each control point affect some well-defined
neighborhood around that point.
67Interpolation
- Bezier curves are approximating. The curve does
not necessarily pass through all the control
points. Wed like to have a curve that is
interpolating, that is, that always passes
through every control points.
68Continuity
- We want our curve to have continuity there
shouldnt be any abrupt changes as we move along
the curve.
69Splines
- We will splice together a curve from individual
Bezier segments. We call these curves splines.
When splicing Bezier together, we need to worry
about continuity.
70Ensuring C0 continuity
711st derivatives at the endpoints
72Ensuring C1 continuity
73The C1 Bezier spline
74Catmull-Rom splines
75Catmull-Rom basis matrix
762nd derivatives at the endpoints
77Ensuring C2 continuity
78A-frames and continuity
79B-spline
80B-spline