文档详情

OpenGL基本图形的绘制.docx

发布:2017-12-08约5.82千字共8页下载文档
文本预览下载声明
1.使用glColor,glPointSize函数绘制三个不同颜色和大小的点// T.cpp : Defines the entry point for the console application.//#include stdafx.h#include gl/glut.h void Display(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(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(); }int main(intargc,char* argv[]) {glutInit(argc,argv);glutInitDisplayMode(GLUT_RGB);glutInitWindowPosition(200,200);glutInitWindowSize(400,400);glutCreateWindow(Three Point);glutDisplayFunc(Display);glutMainLoop();return 0; }2.使用glColor,glLineWidth,glLineStripple函数绘制实心、虚线及渐变色线(1)实心线// T.cpp : Defines the entry point for the console application.//#include stdafx.h#include gl/glut.h void Display(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(); }int main(intargc,char* argv[]) {glutInit(argc,argv);glutInitDisplayMode(GLUT_RGB);glutInitWindowPosition(200,200);glutInitWindowSize(400,400);glutCreateWindow(Solid Line);glutDisplayFunc(Display);glutMainLoop();return 0; }(2)虚线// T.cpp : Defines the entry point for the console application.//#include stdafx.h#include gl/glut.h void Display(void) { 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(); }int main(intargc,char* argv[]) {glutInit(argc,argv);glutInitDisplayMode(GLUT_RGB);glutInitWindowPosition(200,200);glutInitWindowSize(400,400);glutCreateWindow(Dotted Line);glutDisplayFunc(Display);glutMainLoop();return 0; }(3)渐变线// T.cpp : Defines the entry point for the console application.//#include stdafx.h#include gl/glut.h GLuint
显示全部
相似文档