/* A 2D Bezier surface, with 2x3 control points. Written by Scott D. Anderson scott.anderson@acm.org Fall 2007 */ #include #include // for atoi and exit #include #include "bezier-utils.h" const int U_Order = 3; const int V_Order = 2; bool Wirep = true; bool ShowControlPointsp = true; /* ================================================================================ A control-point arrays for a Bezier patches. This is flat (all Z components are zero), and symmetrical across both X and Y. The corners form an 8x4 rectangle. */ GLfloat control_points[U_Order*V_Order*3] = { -4, +2, 0, 0, 0, 0, +4, +2, 0, -4, -2, 0, 0, 0, 0, +4, -2, 0 }; void display(void) { twError(); twDisplayInit(); twCamera(); glPushAttrib(GL_ALL_ATTRIB_BITS); glColor3f(0,1,0); // green patch if(ShowControlPointsp) drawBezierSurfaceControlPoints(U_Order,3,V_Order,3*U_Order,control_points); drawBezierSurface(Wirep?GL_LINE:GL_FILL, U_Order,16,V_Order,16,control_points); twError(); glPopAttrib(); glFlush(); glutSwapBuffers(); } void toggles(unsigned char key, int x, int y) { switch(key) { case 'w': Wirep = !Wirep; break; case 'c': ShowControlPointsp = !ShowControlPointsp; break; } glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500,500); glutCreateWindow(argv[0]); twError(); glutDisplayFunc(display); twError(); twBoundingBox(-4,+4, -2,+2, -1,1); twMainInit(); twKeyCallback('w',toggles,"toggle wireframe"); twKeyCallback('c',toggles,"toggle showing control points"); printBezierSurfaceControlPoints(U_Order,3,V_Order,3*U_Order,control_points); glutMainLoop(); return 0; }