OpenGL Curves - PowerPoint PPT Presentation

About This Presentation
Title:

OpenGL Curves

Description:

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) ... – PowerPoint PPT presentation

Number of Views:83
Avg rating:3.0/5.0
Slides: 27
Provided by: csMon
Category:
Tags: opengl | curves | glint

less

Transcript and Presenter's Notes

Title: OpenGL Curves


1
OpenGL Curves Surfaces
2
Evaluators
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
3
OpenGL 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.

4
Example bezcurve.c
(Note the one I handed out is slightly different
than this one.)
Control Points
Bézier Curve
5
bezcurve.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)

6
glMap1fd ( )
  • 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

7
glMap1 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

8
glEnable(GL_MAP1_VERTEX_3)
  • Enables the one-dimensional evaluator for three
    dimensional vertices.

9
bezcurve.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( )
10
bezcurve.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( )
11
Bezcurve.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.

12
Modification 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)
14
Additional 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( )
15
4 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
16
Calculated Points
17
DEMOS
  • Bezier /wwwf2003/examples/class
  • Curves /wwwf2003/public/curves

18
Another 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()
19
2D Bezier Surfaces
20
(No Transcript)
21
(No Transcript)
22
(No Transcript)
23
(No Transcript)
24
Code is bezmeshnolight.c
25
bezmesh.c with lighting
26
bezsurf.c
Write a Comment
User Comments (0)
About PowerShow.com