/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Avril 2001 */ /* Programmation du calcul */ /* d'une courbe de Bezier OpenGL */ #include #include #include #include #include #include "ModuleCouleurs.h" #include "ModuleFont.h" #include "ModuleManipulateur.h" #include "ModuleMenus.h" #include "ModuleReshape.h" static GLfloat pts[7][3] = { {3,2,-1},{-4,5,-4}, {-5,4,3},{-1,-3,-2}, {4,-1,0}}; void traceBezierGL(void) { glMap1f(GL_MAP1_VERTEX_3, 0.0,1.0,3,5,&pts[0][0]); glEnable(GL_MAP1_VERTEX_3); glColor4fv(couleurCyan()); glBegin(GL_POINTS); for ( int i = 0 ; i <= 100 ; i++ ) glEvalCoord1f((GLfloat) i/100.0F); glEnd(); } void display(void) { int i; glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); glPushMatrix(); glEnable(GL_DEPTH_TEST); manipulateurSouris(); manipulateurClavier(); traceBezierGL() ; glPointSize(5.0); glColor4fv(couleurJaune()); glBegin(GL_POINTS); for ( i = 0 ; i < 5 ; i++ ) glVertex3fv(&pts[i][0]); glEnd(); glPointSize(1.0); glColor4fv(couleurMagenta()); glBegin(GL_LINE_STRIP); for ( i = 0 ; i < 5 ; i++ ) glVertex3fv(&pts[i][0]); glEnd(); glDisable(GL_DEPTH_TEST); glColor4fv(couleurJaune()); for ( i = 0 ; i < 5 ; i++ ) { placeFontCursor(pts[i][0]+0.3F, pts[i][1]+0.3F, pts[i][2]+0.3F); simpleBitmapOutput("%d",i); } glPopMatrix(); glFlush(); glutSwapBuffers(); } void myinit(void) { glClearColor(0.0,0.0,0.0,1.0); glShadeModel(GL_FLAT); glDepthFunc(GL_LESS); } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); glutInitWindowSize(300,300); glutInitWindowPosition(50,50); glutCreateWindow("Courbe de Bezier"); myinit(); creationMenuBasique(); setParametresOrthoBasique(-7.0,7.0,-7.0,7.0,-500.0,500.0); setManipulateurDistance(1.0F); glutReshapeFunc(reshapeOrthoBasique); glutKeyboardFunc(keyBasique); glutSpecialFunc(specialBasique); glutMotionFunc(motionBasique); glutMouseFunc(sourisBasique); glutDisplayFunc(display); glutMainLoop(); return(0); }