#include <GL/glut.h>
#include <math.h>
void myDisplay(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(0.0, 1.0, 0.0);
glVertex2f(-1.0, 1.0);
glColor3f(1.0, 1.0, 0.0);
glVertex2f(1.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.0, -1.0);
glEnd();
int n = 1000, i;
float R = 0.7, Pi = 3.1413926;
glBegin(GL_POLYGON);
glColor3f(1, 0, 1);
for (i = 0; i < n; ++i)
glVertex2f(R * cos(2 * Pi / n * i), R * sin(2 * Pi / n * i));
glEnd();
GLfloat a = 1.2 / (2 - 2 * cos(72 * Pi / 180));
GLfloat bx = a * cos(Pi / 10);
GLfloat by = a * sin(Pi / 10);
GLfloat cy = -a * cos(Pi / 10);
GLfloat
PointA[2] = {0, a},
PointB[2] = {bx, by},
PointC[2] = {0.5, cy},
PointD[2] = {-0.5, cy},
PointE[2] = {-bx, by};
// 按照A->C->E->B->D->A的顺序,可以一笔将五角星画出
glBegin(GL_LINE_LOOP);
glColor3f(0, 0, 1);
glVertex2fv(PointA);
glVertex2fv(PointC);
glVertex2fv(PointE);
glVertex2fv(PointB);
glVertex2fv(PointD);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-0.9, -0.8);
glColor3f(1.0, 0.0, 1.0);
glVertex2f(-0.8, -0.8);
glColor3f(1.0, 1.0, 0.0);
glVertex2f(-0.85, -0.7);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.9, -0.8);
glColor3f(1.0, 1.0, 0.0);
glVertex2f(0.8, -0.8);
glColor3f(0.0, 1.0, 1.0);
glVertex2f(0.85, -0.7);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("Hello Opengl!");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}