第一篇:计算机图形学实验二(包括树林,国旗,彩虹伞,乒乓球台,点线面。
1.乒乓球台源码:
#include “stdafx.h” #include“windows.h” #include“gl/glut.h”
void Inti(){ glClearColor(0.0,0.0,0.0,0.0);} void my(){ glColor3f(0.0,0.5,0.1);glVertex2i(400,850);glVertex2i(400,800);glVertex2i(500,900);glVertex2i(500,950);}
void display(void){ glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2i(200,900);glVertex2i(100,800);glVertex2i(700,800);glVertex2i(800,900);glColor3f(0.0,0.0,1.0);
glVertex2i(125,800);glVertex2i(125,500);glVertex2i(140,500);glVertex2i(140,800);glColor3f(0.0,1.0,0.0);
glVertex2i(200,800);glVertex2i(215,800);glVertex2i(215,600);glVertex2i(200,600);glColor3f(1.0,1.0,0.0);
glVertex2i(665,800);glVertex2i(665,500);glVertex2i(680,500);glVertex2i(680,800);glColor3f(1.0,0.0,1.0);
glVertex2i(770,870);glVertex2i(770,600);glVertex2i(785,600);glVertex2i(785,885);my();glEnd();glFlush();}
void main(int argc, char* argv[]){ glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(1050,1500);glutInitWindowPosition(100,100);glutCreateWindow(“cube”);Inti();gluOrtho2D(0.0,1000.0,0.0,1000);glutDisplayFunc(display);glutMainLoop();
} 运行结果:
2国旗1源码: #include “stdafx.h” #include“windows.h” #include“gl/glut.h” #include“math.h”
void Inti(){ glClearColor(0.0,0.0,0.0,0.0);}
void display(void){ glClear(GL_COLOR_BUFFER_BIT);double v1x=20;double v1y=100;double v2x=20+20*cos(3.1415926/10)/sin(3.1415926/5);double v2y=100;double v3x=30+20*cos(3.1415926/10)/sin(3.1415926/5);double v3y=100-20*cos(3.1415926/10)*cos(3.1415926/10)/sin(3.1415926/5);double v4x=40+20*cos(3.1415926/10)/sin(3.1415926/5);double v4y=100;double v5x=40+40*cos(3.1415926/10)/sin(3.1415926/5);double v5y=100;double v6x=40+20*cos(3.1415926/10)/sin(3.1415926/5)+20*sin(3.1415926/10);double v6y=100+20*cos(3.1415926/10);double v7x=30+20*cos(3.1415926/10)*(1+sin(3*3.1415926/10))/sin(3.1415926/5);double v7y=20*cos(3.1415926/10)*cos(3.1415926/10)/sin(3.1415926/5)+20*cos(3.1415926/10)+100;double v8x=30+20*cos(3.1415926/10)/sin(3.1415926/5);double v8y=20*cos(3.1415926/10)*(cos(3.1415926/10)-cos(3*3.1415926/10))/sin(3.1415926/5)+20*cos(3.1415926/10)+100;double v9x=30+20*cos(3.1415926/10)*(1-sin(3*3.1415926/10))/sin(3.1415926/5);double v9y=20*cos(3.1415926/10)*cos(3.1415926/10)/sin(3.1415926/5)+20*cos(3.1415926/10)+100;double v10x=20+20*cos(3.1415926/10)*cos(3.1415926/5)/sin(3.1415926/5);double v10y=100+20*cos(3.1415926/10);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);
glVertex2f(100,500);glVertex2f(100,10);glVertex2f(105,10);glVertex2f(105,500);
glVertex2f(105,490);glVertex2f(105,365);glVertex2f(300,365);glVertex2f(300,490);
glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_TRUE);glVertex2i(v2x/4+120,v2y/4+425);//v2 glVertex2i(v3x/4+120,v3y/4+425);//v3 glEdgeFlag(GL_FALSE);glVertex2i(v4x/4+120,v4y/4+425);//v4 glVertex2i(v4x/4+120,v4y/4+425);//v4
glEdgeFlag(GL_TRUE);glVertex2i(v6x/4+120,v6y/4+425);//v6 glVertex2i(v5x/4+120,v5y/4+425);//V5 glVertex2i(v6x/4+120,v6y/4+425);//v6
glVertex2i(v7x/4+120,v7y/4+425);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/4+120,v8y/4+425);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/4+120,v8y/4+425);//v8
glVertex2i(v9x/4+120,v9y/4+425);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/4+120,v10y/4+425);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/4+120,v10y/4+425);//v10 glVertex2i(v1x/4+120,v1y/4+425);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/4+120,v2y/4+425);//V2
glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_TRUE);glVertex2i(v2x/9+170,v2y/9+430);//v2 glVertex2i(v3x/9+170,v3y/9+430);//v3 glEdgeFlag(GL_FALSE);glVertex2i(v4x/9+170,v4y/9+430);//v4 glVertex2i(v4x/9+170,v4y/9+430);//v4
glEdgeFlag(GL_TRUE);glVertex2i(v6x/9+170,v6y/9+430);//v6 glVertex2i(v5x/9+170,v5y/9+430);//V5 glVertex2i(v6x/9+170,v6y/9+430);//v6
glVertex2i(v7x/9+170,v7y/9+430);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/9+170,v8y/9+430);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/9+170,v8y/9+430);//v8
glVertex2i(v9x/9+170,v9y/9+430);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/9+170,v10y/9+430);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/9+170,v10y/9+430);//v10 glVertex2i(v1x/9+170,v1y/9+430);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/9+170,v2y/9+430);//V2
glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_TRUE);glVertex2i(v2x/9+170,v2y/9+450);//v2 glVertex2i(v3x/9+170,v3y/9+450);//v3 glEdgeFlag(GL_FALSE);glVertex2i(v4x/9+170,v4y/9+450);//v4 glVertex2i(v4x/9+170,v4y/9+450);//v4
glEdgeFlag(GL_TRUE);glVertex2i(v6x/9+170,v6y/9+450);//v6 glVertex2i(v5x/9+170,v5y/9+450);//V5 glVertex2i(v6x/9+170,v6y/9+450);//v6
glVertex2i(v7x/9+170,v7y/9+450);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/9+170,v8y/9+450);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/9+170,v8y/9+450);//v8
glVertex2i(v9x/9+170,v9y/9+450);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/9+170,v10y/9+450);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/9+170,v10y/9+450);//v10 glVertex2i(v1x/9+170,v1y/9+450);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/9+170,v2y/9+450);//V2
glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_TRUE);glVertex2i(v2x/9+155,v2y/9+465);//v2 glVertex2i(v3x/9+155,v3y/9+465);//v3 glEdgeFlag(GL_FALSE);glVertex2i(v4x/9+155,v4y/9+465);//v4 glVertex2i(v4x/9+155,v4y/9+465);//v4
glEdgeFlag(GL_TRUE);glVertex2i(v6x/9+155,v6y/9+465);//v6 glVertex2i(v5x/9+155,v5y/9+465);//V5 glVertex2i(v6x/9+155,v6y/9+465);//v6
glVertex2i(v7x/9+155,v7y/9+465);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/9+155,v8y/9+465);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/9+155,v8y/9+465);//v8
glVertex2i(v9x/9+155,v9y/9+465);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/9+155,v10y/9+465);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/9+155,v10y/9+465);//v10 glVertex2i(v1x/9+155,v1y/9+465);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/9+155,v2y/9+465);//V2
glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_TRUE);glVertex2i(v2x/9+155,v2y/9+415);//v2 glVertex2i(v3x/9+155,v3y/9+415);//v3 glEdgeFlag(GL_FALSE);glVertex2i(v4x/9+155,v4y/9+415);//v4 glVertex2i(v4x/9+155,v4y/9+415);//v4
glEdgeFlag(GL_TRUE);glVertex2i(v6x/9+155,v6y/9+415);//v6 glVertex2i(v5x/9+155,v5y/9+415);//V5 glVertex2i(v6x/9+155,v6y/9+415);//v6
glVertex2i(v7x/9+155,v7y/9+415);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/9+155,v8y/9+415);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/9+155,v8y/9+415);//v8
glVertex2i(v9x/9+155,v9y/9+415);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/9+155,v10y/9+415);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/9+155,v10y/9+415);//v10 glVertex2i(v1x/9+155,v1y/9+415);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/9+155,v2y/9+415);//V2
glEnd();
glFlush();}
void main(int argc, char* argv[]){ glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
}
glutInitWindowSize(500,500);glutInitWindowPosition(100,100);glutCreateWindow(“cube”);Inti();gluOrtho2D(0.0,600.0,0.0,600.0);glutDisplayFunc(display);glutMainLoop();
运行结果:
3.国旗2源码: #include “stdafx.h” #include“windows.h” #include“gl/glut.h” #include“math.h”
void Inti(){ glClearColor(0.0,0.6,1.0,0.0);}
void display(void){ glClear(GL_COLOR_BUFFER_BIT);double v1x=20;double v1y=100;double v2x=20+20*cos(3.1415926/10)/sin(3.1415926/5);double v2y=100;double v3x=30+20*cos(3.1415926/10)/sin(3.1415926/5);double v3y=100-20*cos(3.1415926/10)*cos(3.1415926/10)/sin(3.1415926/5);double v4x=40+20*cos(3.1415926/10)/sin(3.1415926/5);double v4y=100;double v5x=40+40*cos(3.1415926/10)/sin(3.1415926/5);double v5y=100;double v6x=40+20*cos(3.1415926/10)/sin(3.1415926/5)+20*sin(3.1415926/10);double v6y=100+20*cos(3.1415926/10);double v7x=30+20*cos(3.1415926/10)*(1+sin(3*3.1415926/10))/sin(3.1415926/5);double v7y=20*cos(3.1415926/10)*cos(3.1415926/10)/sin(3.1415926/5)+20*cos(3.1415926/10)+100;double v8x=30+20*cos(3.1415926/10)/sin(3.1415926/5);double v8y=20*cos(3.1415926/10)*(cos(3.1415926/10)-cos(3*3.1415926/10))/sin(3.1415926/5)+20*cos(3.1415926/10)+100;double v9x=30+20*cos(3.1415926/10)*(1-sin(3*3.1415926/10))/sin(3.1415926/5);double v9y=20*cos(3.1415926/10)*cos(3.1415926/10)/sin(3.1415926/5)+20*cos(3.1415926/10)+100;double v10x=20+20*cos(3.1415926/10)*cos(3.1415926/5)/sin(3.1415926/5);double v10y=100+20*cos(3.1415926/10);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);glColor3f(0.1,0.1,0.1);glBegin(GL_QUADS);
glVertex2f(100,500);glVertex2f(100,10);glVertex2f(105,10);glVertex2f(105,500);glColor3f(1.0,0.0,0.0);
glVertex2f(105,490);glVertex2f(105,365);glVertex2f(300,365);glVertex2f(300,490);
glEnd();
glColor3f(1.0,1.0,0.0);glBegin(GL_POLYGON);glVertex2i(v3x/4+120,v3y/4+425);//v3 glVertex2i(v6x/4+120,v6y/4+425);//v6 glVertex2i(v8x/4+120,v8y/4+425);//v8 glVertex2i(v10x/4+120,v10y/4+425);//v10 glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_FALSE);glVertex2i(v4x/4+120,v4y/4+425);//v4
glEdgeFlag(GL_TRUE);glVertex2i(v6x/4+120,v6y/4+425);//v6 glVertex2i(v5x/4+120,v5y/4+425);//V5 glVertex2i(v6x/4+120,v6y/4+425);//v6
glVertex2i(v7x/4+120,v7y/4+425);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/4+120,v8y/4+425);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/4+120,v8y/4+425);//v8
glVertex2i(v9x/4+120,v9y/4+425);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/4+120,v10y/4+425);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/4+120,v10y/4+425);//v10 glVertex2i(v1x/4+120,v1y/4+425);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/4+120,v2y/4+425);//V2
glEnd();
glBegin(GL_POLYGON);glVertex2i(v3x/9+170,v3y/9+430);//v3 glVertex2i(v6x/9+170,v6y/9+430);//v6 glVertex2i(v8x/9+170,v8y/9+430);//v8 glVertex2i(v10x/9+170,v10y/9+430);//v10 glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_FALSE);glVertex2i(v4x/9+170,v4y/9+430);//v4
glEdgeFlag(GL_TRUE);glVertex2i(v6x/9+170,v6y/9+430);//v6 glVertex2i(v5x/9+170,v5y/9+430);//V5 glVertex2i(v6x/9+170,v6y/9+430);//v6
glVertex2i(v7x/9+170,v7y/9+430);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/9+170,v8y/9+430);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/9+170,v8y/9+430);//v8
glVertex2i(v9x/9+170,v9y/9+430);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/9+170,v10y/9+430);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/9+170,v10y/9+430);//v10 glVertex2i(v1x/9+170,v1y/9+430);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/9+170,v2y/9+430);//V2
glEnd();
glBegin(GL_POLYGON);
glVertex2i(v3x/9+170,v3y/9+450);//v3 glVertex2i(v6x/9+170,v6y/9+450);//v6
glVertex2i(v8x/9+170,v8y/9+450);//v8 glVertex2i(v10x/9+170,v10y/9+450);//v10 glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_FALSE);glVertex2i(v4x/9+170,v4y/9+450);//v4 glEdgeFlag(GL_TRUE);glVertex2i(v6x/9+170,v6y/9+450);//v6 glVertex2i(v5x/9+170,v5y/9+450);//V5 glVertex2i(v6x/9+170,v6y/9+450);//v6
glVertex2i(v7x/9+170,v7y/9+450);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/9+170,v8y/9+450);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/9+170,v8y/9+450);//v8
glVertex2i(v9x/9+170,v9y/9+450);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/9+170,v10y/9+450);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/9+170,v10y/9+450);//v10 glVertex2i(v1x/9+170,v1y/9+450);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/9+170,v2y/9+450);//V2
glEnd();
glBegin(GL_POLYGON);glVertex2i(v3x/9+155,v3y/9+465);//v3 glVertex2i(v6x/9+155,v6y/9+465);//v6 glVertex2i(v8x/9+155,v8y/9+465);//v8 glVertex2i(v10x/9+155,v10y/9+465);//v10 glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_FALSE);glVertex2i(v4x/9+155,v4y/9+465);//v4 glEdgeFlag(GL_TRUE);glVertex2i(v6x/9+155,v6y/9+465);//v6 glVertex2i(v5x/9+155,v5y/9+465);//V5 glVertex2i(v6x/9+155,v6y/9+465);//v6
glVertex2i(v7x/9+155,v7y/9+465);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/9+155,v8y/9+465);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/9+155,v8y/9+465);//v8
glVertex2i(v9x/9+155,v9y/9+465);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/9+155,v10y/9+465);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/9+155,v10y/9+465);//v10 glVertex2i(v1x/9+155,v1y/9+465);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/9+155,v2y/9+465);//V2
glEnd();
glBegin(GL_POLYGON);
glVertex2i(v3x/9+155,v3y/9+415);//v3 glVertex2i(v6x/9+155,v6y/9+415);//v6 glVertex2i(v8x/9+155,v8y/9+415);//v8 glVertex2i(v10x/9+155,v10y/9+415);//v10
glEnd();
glBegin(GL_TRIANGLES);glEdgeFlag(GL_FALSE);glVertex2i(v4x/9+155,v4y/9+415);//v4 glEdgeFlag(GL_TRUE);glVertex2i(v6x/9+155,v6y/9+415);//v6 glVertex2i(v5x/9+155,v5y/9+415);//V5 glVertex2i(v6x/9+155,v6y/9+415);//v6
glVertex2i(v7x/9+155,v7y/9+415);//v7
glEdgeFlag(GL_FALSE);
glVertex2i(v8x/9+155,v8y/9+415);//v8 glEdgeFlag(GL_TRUE);
glVertex2i(v8x/9+155,v8y/9+415);//v8
glVertex2i(v9x/9+155,v9y/9+415);//v9
glEdgeFlag(GL_FALSE);glVertex2i(v10x/9+155,v10y/9+415);//v10
glEdgeFlag(GL_TRUE);
glVertex2i(v10x/9+155,v10y/9+415);//v10 glVertex2i(v1x/9+155,v1y/9+415);//V1 glEdgeFlag(GL_FALSE);glVertex2i(v2x/9+155,v2y/9+415);//V2
glEnd();
glFlush();}
void main(int argc, char* argv[]){ glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(500,500);glutInitWindowPosition(100,100);glutCreateWindow(“cube”);Inti();gluOrtho2D(0.0,600.0,0.0,600.0);glutDisplayFunc(display);glutMainLoop();
}
运行结果:
4.森林源码: #include “stdafx.h” #include“windows.h” #include“gl/glut.h”
void Inti(){ glClearColor(0.5,0.5,0.0,0.0);}
void display(void){ glClear(GL_COLOR_BUFFER_BIT);glColor3f(0.0,0.5,0.0);glBegin(GL_QUADS);
glVertex2i(110,300);glVertex2i(70,250);glVertex2i(150,250);glVertex2i(150,250);
glVertex2i(95,250);glVertex2i(40,180);glVertex2i(180,180);glVertex2i(125,250);
glVertex2i(70,180);glVertex2i(10,100);glVertex2i(210,100);glVertex2i(150,180);
glColor3f(0.4,0.4,0.4);glVertex2i(95,100);glVertex2i(95,10);glVertex2i(125,10);glVertex2i(125,100);glEnd();
glColor3f(0.0,0.5,0.0);glBegin(GL_QUADS);
glVertex2i(110+120,300+100);glVertex2i(70+120,250+100);glVertex2i(150+120,250+100);glVertex2i(150+120,250+100);
glVertex2i(95+120,250+100);glVertex2i(40+120,180+100);glVertex2i(180+120,180+100);glVertex2i(125+120,250+100);
glVertex2i(70+120,180+100);glVertex2i(10+120,100+100);glVertex2i(210+120,100+100);glVertex2i(150+120,180+100);
glColor3f(0.4,0.4,0.4);glVertex2i(95+120,100+100);glVertex2i(95+120,10+100);glVertex2i(125+120,10+100);glVertex2i(125+120,100+100);glEnd();
glColor3f(0.0,0.5,0.0);glBegin(GL_QUADS);
glVertex2i(110+250,300+200);glVertex2i(70+250,250+200);glVertex2i(150+250,250+200);glVertex2i(150+250,250+200);
glVertex2i(95+250,250+200);glVertex2i(40+250,180+200);glVertex2i(180+250,180+200);glVertex2i(125+250,250+200);
glVertex2i(70+250,180+200);glVertex2i(10+250,100+200);glVertex2i(210+250,100+200);glVertex2i(150+250,180+200);
glColor3f(0.4,0.4,0.4);glVertex2i(95+250,100+200);glVertex2i(95+250,10+200);glVertex2i(125+250,10+200);glVertex2i(125+250,100+200);glEnd();
glColor3f(0.0,0.5,0.0);glBegin(GL_QUADS);
glVertex2i(110+250,300);glVertex2i(70+250,250);glVertex2i(150+250,250);glVertex2i(150+250,250);
glVertex2i(95+250,250);glVertex2i(40+250,180);glVertex2i(180+250,180);glVertex2i(125+250,250);
glVertex2i(70+250,180);glVertex2i(10+250,100);glVertex2i(210+250,100);glVertex2i(150+250,180);
glColor3f(0.4,0.4,0.4);glVertex2i(95+250,100);glVertex2i(95+250,10);glVertex2i(125+250,10);glVertex2i(125+250,100);glEnd();
glFlush();}
void main(int argc, char* argv[]){ glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(500,500);glutInitWindowPosition(100,100);glutCreateWindow(“cube”);Inti();gluOrtho2D(0.0,500.0,0.0,500.0);glutDisplayFunc(display);glutMainLoop();
}
运行结果:
5.点,线,面源码: #include “stdafx.h” #include “gl/glut.h” #include“windows.h” void init()//应用程序初始化
{
glClearColor(0.0,.0,0.0,0.0);// 设置背景颜色为白色 }
void display(void){ glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,0.0);
glBegin(GL_POINTS);
glVertex2f(20,50);
glVertex2f(54,50);
glVertex2f(30,30);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2f(40,40);
glVertex2f(80,30);
glVertex2f(60,60);
glEnd();
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);glBegin(GL_TRIANGLES);
glVertex2f(20,150);
glVertex2f(80,80);
glVertex2f(99,90);
glEnd();glBegin(GL_QUADS);
glVertex2f(100,180);
glVertex2f(100,100);
glVertex2f(180,100);glVertex2f(180,180);glEnd();
glBegin(GL_POLYGON);glVertex2f(200,180);
glVertex2f(250,300);
glVertex2f(300,300);glVertex2f(250,180);glVertex2f(220,170);glEnd();glFlush();} void main(int argc,char** argv){ glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(500,500);glutInitWindowPosition(200,200);glutCreateWindow(“点,线,面”);init();gluOrtho2D(0.0,500.0,0.0,500.0);glutDisplayFunc(display);glutMainLoop();}
运行结果:
6.伞源码 :
#include “stdafx.h” #include
glClearColor(0.0,0.0,0.0,0.0);}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.3,0.3);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glBegin(GL_POLYGON);
glVertex2f(200.0,300.0);
glVertex2f(197.5,250.0);
glVertex2f(197.5,40.0);
glVertex2f(202.5,40.0);
glVertex2f(202.5,250.0);
glEnd();
glBegin(GL_QUADS);
glVertex2f(195.0,40.0);
glVertex2f(195.0,10.0);
glVertex2f(205.0,10.0);
glVertex2f(205.0,40.0);
glEnd();glColor3f(1.0,0.0,0.0);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(200.0,300.0);
glVertex2f(50.0,220.0);
glVertex2f(110.0,192.5);
glColor3f(0.0,1.0,0.0);
glVertex2f(200.0,300.0);
glVertex2f(110.0,192.5);
glVertex2f(200.0,180.0);
glColor3f(0.0,0.0,1.);
glVertex2f(200.0,300.0);
glVertex2f(200.0,180.0);
glVertex2f(290.0,192.5);
glColor3f(1.0,1.0,0.0);
glVertex2f(200.0,300.0);
glVertex2f(290.0,192.5);
glVertex2f(350.0,220.0);
glEnd();glFlush();} void Myreshape(GLsizei w,GLsizei h){
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)w,0.0,(GLdouble)h);}
int main(int argc, char* argv[]){ glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(400,400);
glutInitWindowPosition(150,150);
glutCreateWindow(“Point”);
myinit();
glutDisplayFunc(display);
glutReshapeFunc(Myreshape);
glutMainLoop();
}
运行结果: