Title: OpenGL Curves
1OpenGL Curves Surfaces
2Evaluators
A Bezier curve is a vector-valued function of 1
variable
Where u varies in some domain (say 0,1). A
Bezier surface patch is a vector-valued function
of two variables
3OpenGL Evaluator
- Define the function C( ) or S( )
- Enable it
- Use glEvalCoord1( ) or glEvalCoord2( ) instead of
glVertex( ) - The curve or surface is used just as any other
vertices are used.
4Example bezcurve.c
(Note the one I handed out is slightly different
than this one.)
Control Points
Bézier Curve
5bezcurve.c (part 1)
GLfloat ctrlpoints43 -4.0, -4.0,
0.0, -2.0, 4.0, 0.0, 2.0, -4.0,
0.0, 4.0, 4.0, 0.0
void init(void) glClearColor(0.0, 0.0, 0.0,,
0.0) glShadeModel(GL_FLAT)
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4,
ctrlpoints00) glEnable(GL_MAP1_VERTEX_3)
6glMap1fd ( )
- GLenum target (see next slide)
- TYPE u1 starting value of u
- TYPE u2 ending value of u
- GLint stride number of single or double
precision values in each block of storage. - GLint order degree plus 1 (should agree with
the number of control points) - const TYPE points pointer to control points
7glMap1 target parameter
- GL_MAP1_TEXTURE_COORD_2 s,t texture coordinates
- GL_MAP1_TEXTURE_COORD_3 s,t,r texture
coordinates - GL_MAP1_TEXTURE_COORD_4 s,t,r,q texture
coordinates
- GL_MAP1_VERTEX_3 x,y,z vertex coordinates
- GL_MAP1_VERTEX_4 x,y,z,w vertex coordinates
- GL_MAP1_INDEX color index
- GL_MAP1_COLOR_4 R,G,B,A
- GL_MAP1_NORMAL normal coordinates
- GL_MAP1_TEXTURE_COORD_1 s texture coordinate
8glEnable(GL_MAP1_VERTEX_3)
- Enables the one-dimensional evaluator for three
dimensional vertices.
9bezcurve.c (part 2) display function
void display(void) int i
glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0,
1.0, 1.0) // set color to white
glBegin(GL_LINE_STRIP) for(i0 ilt30 i)
// loop 31 times glEvalCoord1f((GLfloat)
i/30.0) // call evaluator glEnd( )
10bezcurve.c (part 3)
/ the following code displays the control points
as dots / glPointSize(5.0) glColor3f(1.0, 1.0,
0.0) // set color to yellow glBegin(GL_POINTS)
for(i0 ilt4 i) glVertex3fv(ctrlointsi
0) // Draw a point glEnd( ) glFlush( )
11Bezcurve.c (part 4)
- A reshape function that uses glOrtho for
orthographic projections and an identity matrix
for model view. - A normal main function like all other examples.
12Modification for hand-out
- I changed the color of the bezier curve to red
and added another bezier curve with different
parameters. - Only 4 steps in the evaluator loop.
- (This new curve is drawn in white)
- Note the lack of smoothness.
- Note the same start and end points.
13(No Transcript)
14Additional code
glClear(GL_COLOR_BUFFER_BIT) // clear
screen glColor3f(1.0, 1.0, 1.0) // set
color to white glBegin(GL_LINE_STRIP) //
start a line strip for(i0 ilt4 i)
// loop FIVE times glEvalCoord1f((GLfloat)i/4
.0) // calc a point glEnd( ) glColor3f(1.0,
0.0, 0.0) // set color to
red glBegin(GL_LINE_STRIP) // start a
line strip for(i0 ilt30 i) // loop
31 times glEvalCoord1f((GLfloat)i/30.0) //
calc a point glEnd( )
154 4.0/4.0 1.0
3 3.0/4.0 0.75
2 2.0/4.0 0.50
15 15.0/30.00.50
1 1.0/4.0 0.25
0 0.0/4.0 0.0
16Calculated Points
17DEMOS
- Bezier /wwwf2003/examples/class
- Curves /wwwf2003/public/curves
18Another way to do even spacing
- void glMapGrid1fd(GLint n, TYPE u1, TYPE u2)
- Void glEvalMesh1(GLenum mode, GLint p1, GLint
p2) (equivalent to following)
glBegin(GL_POINTS) // or glBegin(GL_LINE_STRIP)
for (ip1 iltp2 i) glEvalCoord1(u1i(u2-
u1)/n) glEnd()
192D Bezier Surfaces
20(No Transcript)
21(No Transcript)
22(No Transcript)
23(No Transcript)
24Code is bezmeshnolight.c
25bezmesh.c with lighting
26bezsurf.c