#include #include #define PI 3.1415 void drawCircle(GLdouble x, GLdouble y, GLdouble r, GLint circle_points) { double red = 1.0; double green = 0.0; double blue = 0.0; double alpha = 2 * PI / circle_points; glBegin(GL_POLYGON); // glBegin(GL_LINE_LOOP); for (int i= 0; i< circle_points; i++) { glColor3f(red, green, blue); red -= 1.0 / circle_points; green += 1.0 / circle_points; double angle = i * alpha; glVertex2f(x + r * cos(angle), y + r * sin(angle)); } glEnd(); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); drawCircle(0.5, 0.5, 0.2, 36); glFlush(); } void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(650, 650); glutInitWindowPosition(670, 330); glutCreateWindow("hello"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }