#includewindows.h#includegl/glut.h#includemath.hGLintnNumPoints=4;//控制点个数/*存储控制点*/GLfloatctrlPoints[4][3]={{-4.0f,-2.0f,0.0f},{-2.0f,2.0f,0.0f},{2.0f,3.0f,0.0f},{4.0f,-1.0f,0.0f}};voidmyinit(void){glClearColor(1.0f,1.0f,1.0f,1.0f);/*一维求值器:定义Bezier曲线方程*/glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,nNumPoints,&ctrlPoints[0][0]);glEnable(GL_MAP1_VERTEX_3);glShadeModel(GL_FLAT);}voiddisplay(void){GLinti;glClear(GL_COLOR_BUFFER_BIT);/*画Bezier曲线*/glColor3f(0.0,0.0,0.0);glBegin(GL_LINE_STRIP);for(i=0;i=100;i++)glEvalCoord1f((GLfloat)i/100.0);glEnd();/*画控制点*/glColor3f(0.0,0.0,1.0);glPointSize(5.0f);glBegin(GL_POINTS);for(i=0;inNumPoints;i++)glVertex3fv(&ctrlPoints[i][0]);glEnd();/*画控制多边形*/glBegin(GL_LINE_STRIP);for(i=0;inNumPoints;i++)glVertex3fv(&ctrlPoints[i][0]);glEnd();glFlush();}voidmyReshape(intw,inth){glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();if(w=h)glOrtho(-5.0,5.0,-5.0*(GLfloat)h/(GLfloat)w,5.0*(GLfloat)h/(GLfloat)w,-5.0,5.0);elseglOrtho(-5.0*(GLfloat)w/(GLfloat)h,5.0*(GLfloat)w/(GLfloat)h,-5.0,5.0,-5.0,5.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}intmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(200,200);glutInitWindowPosition(100,100);glutCreateWindow(colorcube);myinit();glutDisplayFunc(display);glutReshapeFunc(myReshape);glutMainLoop();return0;}控制点4个,坐标{-4.0f,-3.0f,0.0f},{-2.0f,3.0f,0.0f},{2.0f,-4.0f,0.0f},{3.0f,3.5f,0.0f}图形控制点5个,坐标{-4.0f,-3.0f,0.0f},{-2.0f,3.0f,0.0f},{2.0f,-4.0f,0.0f},{3.0f,3.5f,0.0f},{-4.0f,-2.0f,0.0f}图形控制点5个,坐标{-4.0f,-3.0f,0.0f},{-2.0f,3.0f,0.0f},{2.0f,-4.0f,0.0f},{3.0f,3.5f,0.0f},{-4.0f,-2.0f,0.0f}glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,4,nNumPoints,&ctrlPoints[0][0]);图形控制点5个,坐标{-4.0f,-3.0f,0.0f},{-2.0f,3.0f,0.0f},{2.0f,-4.0f,0.0f},{3.0f,3.5f,0.0f},{-4.0f,-2.0f,0.0f}glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,2,nNumPoints,&ctrlPoints[0][0]);图形控制点4个,坐标{-4.0f,-3.0f,0.0f},{-2.0f,3.0f,0.0f},{2.0f,-4.0f,0.0f},{3.0f,3.5f,0.0f},{-4.0f,-2.0f,0.0f}glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,2,nNumPoints,&ctrlPoints[0][0]);图形#includestdafx.h#includewindows.h#includegl/glut.h#includemath.hGLintnNumPoints=3;//控制点个数/*存储控制点*/GLfloatctrlPoints[3][3][3]={{{-4.0f,-1.0f,4.0f},{0.0f,2.0f,4.0f},{4.0f,-1.0f,4.0f}},{{-4.0f,-1.0f,0.0f},{0.0f,2.0f,0.0f},{4.0f,-1.0f,0.0f}},{{-4.0f,-1.0f,-4.0f},{0.0f,2.0f,-4.0f},{4.0f,-1.0f,-4.0f}}};voidmyinit(void){glClearColor(1.0f,1.0f,1.0f,1.0f);/*定义二维求值器*/glMap2f(GL_MAP2_VERTEX_3,0.0,1.0,3,3,0.0,1.0,9,3,&ctrlPoints[0][0][0]);glEnable(GL_MAP2_VERTEX_3);glEnable(GL_DEPTH_TEST);glShadeModel(GL_FLAT);}voiddisplay(void){GLinti,j;glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glColor3f(0.0,0.0,0.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glPushMatrix();glRotatef(60.0f,1.0f,1.0f,1.0f);for(j=0;j=10;j++){glBegin(GL_LINE_STRIP);for(i=0;i=50;i++)glEvalCoord2f((GLfloat)i/50.0,(GLfloat)j/10.0);glEnd();glBegin(GL_LINE_STRIP);for(i=0;i=50;i++)glEvalCoord2f((GLfloat)j/10.0,(GLfloat)i/50.0);glEnd();}glPointSize(5.0f);glColor3f(0.0,0.0,1.0);glBegin(GL_POINTS);for(i=0;inNumPoints;i++)for(j=0;j3;j++)glVertex3fv(ctrlPoints[i][j]);glEnd();for(j=0;j3;j++){glBegin(GL_LINE_STRIP);for(i=0;inNumPoints;i++)glVertex3fv(ctrlPoints[i][j]);glEnd();}for(j=0;j3;j++){glBegin(GL_LINE_STRIP);for(i=0;i3;i++)glVertex3fv(ctrlPoints[j][i]);glEnd();}glPopMatrix();glFlush();}voidmyReshape(intw,inth){glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();if(w=h)glOrtho(-7.0,7.0,-7.0*(GLfloat)h/(GLfloat)w,7.0*(GLfloat)h/(GLfloat)w,-5.0,5.0);elseglOrtho(-7.0*(GLfloat)w/(GLfloat)h,7.0*(GLfloat)w/(GLfloat)h,-7.0,7.0,-5.0,5.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}intmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(200,200);glutInitWindowPosition(100,100);glutCreateWindow(colorcube);myinit();glutDisplayFunc(display);glutReshapeFunc(myReshape);glutMainLoop();return0;}GLfloatctrlPoints[4][4][3]={{{-2.5f,-1.5f,2.0f},{-1.5f,-1.5f,2.6f},{0.5f,-1.5f,-2.0f},{1.5f,-1.5f,2.0f}},{{-1.5f,-0.5f,1.0f},{-0.5f,1.5f,2.0f},{0.5f,0.5f,1.0f},{1.5f,-0.5f,-1.0f}},{{-1.0f,0.5f,2.0f},{-0.5f,0.5f,1.6f},{0.8f,0.5f,3.0f},{1.5f,-2.5f,1.5f}},{{-1.5f,1.5f,-2.0f},{-0.5f,1.5f,-2.0f},{0.5f,0.5f,2.0f},{2.5f,1.5f,-1.5f}}};glMap2f(GL_MAP2_VERTEX_3,0.0,1.0,3,4,0.0,1.0,12,4,&ctrlPoints[0][0][0]);仅画曲线图形控制多边形glColor3f(0.0,0.0,1.0);for(j=0;j3;j++){glBegin(GL_LINE_STRIP);for(i=0;inNumPoints;i++)glVertex3fv(ctrlPoints[i][j]);glEnd();}for(j=0;j3;j++){glBegin(GL_LINE_STRIP);for(i=0;i3;i++)glVertex3fv(ctrlPoints[j][i]);glEnd();}