首页 > 代码库 > OpenGL基础(一)画多边形

OpenGL基础(一)画多边形

 1 //Five edges polygon.
 2 //As less code as possible.
 3 
 4 #include "stdafx.h"
 5 #include<gl/glut.h>
 6 #include<stdlib.h>
 7 
 8 void init(void)
 9 {
10     glClearColor(0.0, 0.0, 0.0, 0.0);
11 }
12 
13 void display(void)
14 {
15     glClear(GL_COLOR_BUFFER_BIT);
16 
17 
18     glBegin(GL_POLYGON);
19     glColor3f(1.0, 1.0, 1.0);
20     glVertex3f(-1.0, 0.0, 0.0);
21 
22     glColor3f(1.0, 1.0, 0.0);
23     glVertex3f(0.0, 1.0, 0.0);
24 
25     glColor3f(1.0, 0.0, 1.0);
26     glVertex3f(1.0, 0.0, 0.0);
27 
28     glColor3f(0.0, 1.0, 1.0);
29     glVertex3f(0.5, -1.0, 0.0);
30 
31     glColor3f(0.0, 0.0, 1.0);
32     glVertex3f(-0.5, -1.0, 0.0);
33     glEnd();
34     glFlush();
35 
36 }
37 
38 
39 int main(int argc, char** argv)
40 {
41     glutInit(&argc, argv);
42     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
43     glutInitWindowPosition(500, 300);
44     glutInitWindowSize(500, 500);
45     glutCreateWindow("SimplePentage");
46     init();
47     glutDisplayFunc(display);
48     glutMainLoop();
49     return 0;
50 }

 

OpenGL基础(一)画多边形