#include "stdafx.h"#include#include #include #include #include #include #include #include using namespace std;const GLdouble PI = 3.14159265357;void myDisplay(void) { //glShadeModel(GL_FLAT); glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLE_FAN); glColor3f(1.0f, 1.0f, 1.0f); glVertex2f(0.0f, 0.0f); for (int i = 0; i <= 8; i++) { glVertex2f(cos(i*PI / 4), sin(i*PI / 4)); } glEnd(); glFlush();}int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(100, 100); glutInitWindowSize(500, 500); glutCreateWindow("多边形 OpenGL 程序"); glutDisplayFunc(&myDisplay); glutMainLoop(); return 0;}
运行结果如下所示: