实验一 OpenGL初识

主题:实验1——OpenGL初识(计算机图形学(OpenGL版))

代码1:

 1 #include 
 2 
 3 void myDisplay(void){
 4 
 5 glClearColor(0.0,0.0,0.0,0.0);
 6 glClear(GL_COLOR_BUFFER_BIT);
 7 
 8 glColor3f(1.0f,1.0f,1.0f);
 9 glRectf(-0.5f,-0.5f,0.5f,0.5f);
10 
11 glBegin (GL_TRIANGLES);
12 glColor3f(1.0f,0.0f,0.0f);glVertex2f(0.0f,1.0f);
13 glColor3f(0.0f,1.0f,0.0f);glVertex2f(0.8f,-0.5f);
14 glColor3f(0.0f,0.0f,1.0f);glVertex2f(-0.8f,-0.5f);
15 glEnd();
16 
17 glPointSize(3);
18 
19 glBegin(GL_POINTS);
20 
21 glColor3f(1.0f,0.0f,0.0f);glVertex2f(-0.4f,-0.4f);
22 glColor3f(0.0f,1.0f,0.0f);glVertex2f(0.0f,0.0f);
23 glColor3f(0.0f,0.0f,1.0f);glVertex2f(0.4f,0.4f);
24 
25 glEnd();
26 
27 
28 glFlush();
29 
30 
31 }
32 
33 int main(int argc,char *argv[]){
34     glutInit(&argc,argv);
35     glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
36     glutInitWindowPosition(100,100);
37     glutInitWindowSize(400,400);
38     glutCreateWindow("Hello World!");
39     glutDisplayFunc(&myDisplay);
40     glutMainLoop();
41     return 0;
42 
43 }

运行结果:

实验一 OpenGL初识_第1张图片

 

代码2:

 1 #include 
 2 
 3 void myDisplay(void){
 4 
 5 glClearColor(0.0,0.0,0.0,0.0);
 6 glClear(GL_COLOR_BUFFER_BIT);
 7 
 8 glColor3f(1.0f,1.0f,1.0f);
 9 glRectf(-0.5f,-0.5f,0.5f,0.5f);
10 
11 glBegin (GL_TRIANGLES);
12 glColor3f(1.0f,0.0f,0.0f);glVertex2f(0.0f,1.0f);
13 glColor3f(0.0f,1.0f,0.0f);glVertex2f(0.8f,-0.5f);
14 glColor3f(0.0f,0.0f,1.0f);glVertex2f(-0.8f,-0.5f);
15 glEnd();
16 
17 glPointSize(3);
18 
19 glBegin(GL_POINTS);
20 
21 glColor3f(1.0f,0.0f,0.0f);glVertex2f(-0.4f,-0.4f);
22 glColor3f(0.0f,1.0f,0.0f);glVertex2f(0.0f,0.0f);
23 glColor3f(0.0f,0.0f,1.0f);glVertex2f(0.4f,0.4f);
24 
25 glEnd();
26 
27 
28 glBegin(GL_LINE_LOOP);
29 
30 glColor3f(1.0f,1.0f,1.0f);glVertex2f(0.4f,0.25f);
31 glColor3f(1.0f,1.0f,1.0f);glVertex2f(0.0f,-0.5f);
32 glColor3f(1.0f,1.0f,1.0f);glVertex2f(-0.4f,0.25f);
33 
34 glEnd();
35 
36 glFlush();
37 
38 
39 }
40 
41 int main(int argc,char *argv[]){
42     glutInit(&argc,argv);
43     glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
44     glutInitWindowPosition(100,100);
45     glutInitWindowSize(400,400);
46     glutCreateWindow("Hello World!");
47     glutDisplayFunc(&myDisplay);
48     glutMainLoop();
49     return 0;
50 
51 }

运行结果:

实验一 OpenGL初识_第2张图片

转载于:https://www.cnblogs.com/mallocxw/p/5366623.html

你可能感兴趣的:(实验一 OpenGL初识)