Bezier Curve
Bezier Curve
Bezier Curve
Develop a menu driven program to animate a flag using Bezier Curve algorithm
#include<GL/glut.h>
#include<stdio.h>
#include<math.h>
#define pi 3.1416
static float th = 0;
GLint nCP = 4, nBCP = 20;
typedef struct wc
{
GLfloat x, y, z;
};
void display()
{
glClearColor(0, 0, 0, 1);
}
void draw_and_animate()
{
wc cP[4] = { { 20,100,0 },{ 30,110,0 },{ 50,90,0 },{ 60,100,0 } };
th += 0.1;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 1, 1);
glPushMatrix();
glLineWidth(5);
glPopMatrix();
glutPostRedisplay();
glutSwapBuffers();
}
case 2:glutIdleFunc(NULL);
break;
}
glutPostRedisplay();
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(50, 50);
glutInitWindowSize(640, 840);
glutCreateWindow("Bezier Curve");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glClearColor(0, 0, 0, 1);
glFlush();
glutCreateMenu(menu);
glutAddMenuEntry("Draw and animate", 1);
glutAddMenuEntry("Stop animation", 2);
glutAttachMenu(GLUT_LEFT_BUTTON);
glutMainLoop();
return 0;
}
Output