/* Auteur: Nicolas JANEY */ /* Avril 2001 */ /* Programmation du calcul */ /* d'une courbe de Bezier OpenGL */ #include #include #include #include #include #include #include "modulefont.h" static GLfloat view_rotx=0.0F ; static GLfloat view_roty=0.0F ; static GLfloat view_rotz=0.0F ; 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); glColor3f(0.0,1.0,1.0); glBegin(GL_POINTS); for ( int i = 0 ; i <= 100 ; i++ ) glEvalCoord1f((GLfloat) i/100.0F); glEnd(); } void CALLBACK display(void) { int i; glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); glPushMatrix(); glEnable(GL_DEPTH_TEST); glRotatef(view_rotx,1.0,0.0,0.0); glRotatef(view_roty,0.0,1.0,0.0); glRotatef(view_rotz,0.0,0.0,1.0); traceBezierGL() ; glPointSize(5.0); glColor3f(1.0,1.0,0.0); glBegin(GL_POINTS); for ( i = 0 ; i < 5 ; i++ ) glVertex3fv(&pts[i][0]); glEnd(); glPointSize(1.0); glColor3f(1.0,0.0,1.0); glBegin(GL_LINE_STRIP); for ( i = 0 ; i < 5 ; i++ ) glVertex3fv(&pts[i][0]); glEnd(); glDisable(GL_DEPTH_TEST); glColor3f(1.0,1.0,0.0); for ( i = 0 ; i < 5 ; i++ ) { glRasterPos3f(pts[i][0]+0.3F, pts[i][1]+0.3F, pts[i][2]+0.3F); char st[50] ; sprintf(st,"%d",i); printString(st); } glPopMatrix(); glFlush(); auxSwapBuffers(); } void CALLBACK myReshape(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if( w <= h ) { float y = 7.F*(float)h/(float)w ; glOrtho(-7.,7.,-y,y,-7.,7.); } else { float x = 7.F*(float)w/(float)h ; glOrtho(-x,x,-7.,7.,-7.,7.); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void myinit(void) { makeRasterFont(); glClearColor(0.0,0.0,0.0,1.0); glShadeModel(GL_FLAT); glDepthFunc(GL_LESS); } void CALLBACK keyx(void) { view_rotx += 2 ; } void CALLBACK keyX(void) { view_rotx -= 2 ; } void CALLBACK keyy(void) { view_roty += 2 ; } void CALLBACK keyY(void) { view_roty -= 2 ; } void CALLBACK keyz(void) { view_rotz += 2 ; } void CALLBACK keyZ(void) { view_rotz -= 2 ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA|AUX_DEPTH); auxInitPosition(0,0,300,300); auxInitWindow("Courbe de Bezier"); myinit(); auxKeyFunc(AUX_x,keyx) ; auxKeyFunc(AUX_X,keyX) ; auxKeyFunc(AUX_y,keyy) ; auxKeyFunc(AUX_Y,keyY) ; auxKeyFunc(AUX_z,keyz) ; auxKeyFunc(AUX_Z,keyZ) ; auxReshapeFunc(myReshape); auxMainLoop(display); }