资源描述:
《OpenGL基本图形的绘制》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.使用glColor,glPointSize函数绘制三个不同颜色和大小的点//T.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#includevoidDisplay(void){glClear(GL_COLOR_BUFFER_BIT);glPointSize(5.0f);glBegin(GL_POINTS);glColor3f(1.0,0.0,0.0);glVertex2f(0.3f,0.5f);glEnd();glPointSize(
2、8.0f);glBegin(GL_POINTS);glColor3f(0.0,1.0,0.0);glVertex2f(0.0f,0.0f);glEnd();glPointSize(10.0f);glBegin(GL_POINTS);glColor3f(0.0,0.0,1.0);glVertex2f(-0.3f,-0.5f);glEnd();glFlush();}intmain(intargc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB);glutInitWindowPos
3、ition(200,200);glutInitWindowSize(400,400);glutCreateWindow("ThreePoint");glutDisplayFunc(&Display);glutMainLoop();return0;}2.使用glColor,glLineWidth,glLineStripple函数绘制实心、虚线及渐变色线(1)实心线//T.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#includevoidD
4、isplay(void){glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);glEnable(GL_LINE_STIPPLE);glShadeModel(GL_SMOOTH);glLineStipple(2,0xFFFF);glLineWidth(2);glBegin(GL_LINES);glVertex2i(-100,0);glVertex2i(100,0);glEnd();glFlush();}intmain(intargc,char*argv[]){glutInit(&argc,argv);g
5、lutInitDisplayMode(GLUT_RGB);glutInitWindowPosition(200,200);glutInitWindowSize(400,400);glutCreateWindow("SolidLine");glutDisplayFunc(&Display);glutMainLoop();return0;}(2)虚线//T.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#includevoidDisplay(v
6、oid){glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);glEnable(GL_LINE_STIPPLE);glShadeModel(GL_SMOOTH);glLineStipple(4,0xAAAA);glLineWidth(2);glBegin(GL_LINES);glVertex2i(-100,0);glVertex2i(100,0);glEnd();glFlush();}intmain(intargc,char*argv[]){glutInit(&argc,argv);glutInitD
7、isplayMode(GLUT_RGB);glutInitWindowPosition(200,200);glutInitWindowSize(400,400);glutCreateWindow("DottedLine");glutDisplayFunc(&Display);glutMainLoop();return0;}(3)渐变线//T.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#includeGLuintLine;voidInit
8、ial(void){glClearColor(0.0f,0.0f,0.0f,0.0f);Lin