Presentation is loading. Please wait.

Presentation is loading. Please wait.

OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A.

Similar presentations


Presentation on theme: "OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A."— Presentation transcript:

1 OpenGL Curves & Surfaces

2 Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A Bezier curve is a vector-valued function of 1 variable

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 ctrlpoints[4][3] = { {-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, &ctrlpoints[0][0]); glEnable(GL_MAP1_VERTEX_3);}

6 glMap1{fd} ( … ) 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_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 GL_MAP1_TEXTURE_COOR D_2 : s,t texture coordinates GL_MAP1_TEXTURE_COOR D_3 : s,t,r texture coordinates GL_MAP1_TEXTURE_COOR D_4 : s,t,r,q texture coordinates

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(i=0; i<=30; 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(i=0; i<4; i++) glVertex3fv(&ctrloints[i][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

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(i=0; i<=4; 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(i=0; i<=30; i++); // loop 31 times glEvalCoord1f((GLfloat)i/30.0); // calc a point glEnd( );

15 0 : 0.0/4.0 = 0.0 2 : 2.0/4.0 = 0.50 1 : 1.0/4.0 = 0.25 3 : 3.0/4.0 = 0.75 4 : 4.0/4.0 = 1.0 15 : 15.0/30.0=0.50

16 Calculated Points

17 DEMOS Bezier /wwwf2003/examples/class Curves /wwwf2003/public/curves

18 Another way to do even spacing void glMapGrid1{fd}(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 (i=p1; i<=p2; i++) glEvalCoord1(u1+i*(u2-u1)/n); glEnd();

19 2D Bezier Surfaces

20

21

22

23

24 Code is bezmeshnolight.c

25 bezmesh.c with lighting

26 bezsurf.c


Download ppt "OpenGL Curves & Surfaces. Where u varies in some domain (say [0,1]). A Bezier surface patch is a vector-valued function of two variables Evaluators A."

Similar presentations


Ads by Google