利用OpenGL-绘制基本图元-五角星

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实验1:利用OpenGL绘制基本图元1、实验要求和目的:a、掌握vc++程序开发环境,熟悉OpenGL基本程序结构。b、掌握基本图元的绘制方法。2、实验内容:a、点、线、三角形、多边形的绘制3、实验步骤:a、OpenGL相关库文件的安装;b、新建工程,OpenGL相关.lib链接,.cpp文件中包含相关.h文件c、输入、调试、运行OpenGL绘制基本图元的程序。d、设计五角星(填充)及过渡色扇面(三角,四角)的生成算法的实现程序。4、实验代码#includestdlib.h#includestdio.h#includeGL/glut.h#includeiostream.h#includemath.hvoidmyDraw(){glClear(GL_COLOR_BUFFER_BIT);glColor3f(0.0,0.0,1.0);glPointSize(1.0);/*假设五角星外接圆半径为1,有一个角朝上,以五角星中心为原点:则五个角顶点坐标分别为(按顺时针):A(0,1)B(cos18°,sin18°)C(cos54°,-sin54°)D(-cos54°,-sin54°)E(-cos18°,sin18°)假设t为内部五边形外接圆半径,t=(1+tan^2(18°))/(3-tan^2(18°)),即0.3819660112501则五个顶点所对应的坐标为(即内部五边形的五个顶点):BB(-t*cos18°,-t*sin18°)3CC(-t*cos54°,t*sin54°)2DD(t*cos54°,t*sin54°)1AA(0,-t)4EE(t*cos18°,-t*sin18°)5*///upglBegin(GL_TRIANGLES);//绘制三角形glVertex3f(0.0f,1.0f,0.0f);//上顶点glVertex3f(0.38f*cos(54*3.14/180.0),0.38f*sin(54*3.14/180.0),0.0f);//1glVertex3f(-0.38f*cos(54*3.14/180.0),0.38f*sin(54*3.14/180.0),0.0f);//2glEnd();glColor3f(0.0,1.0,1.0);//left-upglBegin(GL_TRIANGLES);//绘制三角形glVertex3f(-1.0f*cos(18*3.14/180.0),1.0*sin(18*3.14/180.0),0.0f);//glVertex3f(-0.38f*cos(54*3.14/180.0),0.38f*sin(54*3.14/180.0),0.0f);//2glVertex3f(-0.38f*cos(18*3.14/180.0),-0.38f*sin(18*3.14/180.0),0.0f);//3glEnd();glColor3f(1.0,0.0,1.0);//left-downglBegin(GL_TRIANGLES);//绘制三角形glVertex3f(-1.0f*cos(54*3.14/180.0),-1.0*sin(54*3.14/180.0),0.0f);//glVertex3f(-0.38f*cos(18*3.14/180.0),-0.38f*sin(18*3.14/180.0),0.0f);//3glVertex3f(0.0,-0.38f,0.0f);//4glEnd();glColor3f(0.0,1.0,0.0);//right-downglBegin(GL_TRIANGLES);//绘制三角形glVertex3f(1.0f*cos(54*3.14/180.0),-1.0f*sin(54*3.14/180.0),0.0f);glVertex3f(0.0,-0.38f,0.0f);//4glVertex3f(0.38f*cos(18*3.14/180.0),-0.38f*sin(18*3.14/180.0),0.0f);//5glEnd();glColor3f(1.0,0.4,0.5);//right-upglBegin(GL_TRIANGLES);//绘制三角形glVertex3f(1.0f*cos(18*3.14/180.0),1.0*sin(18*3.14/180.0),0.0f);//glVertex3f(0.38f*cos(18*3.14/180.0),-0.38f*sin(18*3.14/180.0),0.0f);//5glVertex3f(0.38f*cos(54*3.14/180.0),0.38f*sin(54*3.14/180.0),0.0f);//1glEnd();glColor3f(0.5,1.0,1.0);glBegin(GL_POLYGON);glVertex3f(0.38f*cos(54*3.14/180.0),0.38f*sin(54*3.14/180.0),0.0f);//1glVertex3f(-0.38f*cos(54*3.14/180.0),0.38f*sin(54*3.14/180.0),0.0f);//2glVertex3f(-0.38f*cos(18*3.14/180.0),-0.38f*sin(18*3.14/180.0),0.0f);//3glVertex3f(0.0,-0.38f,0.0f);//4glVertex3f(0.38f*cos(18*3.14/180.0),-0.38f*sin(18*3.14/180.0),0.0f);//5glEnd();glFlush();}intmain(intargc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(500,500);glutInitWindowPosition(0,0);glutCreateWindow(SterpinskiTriangle);glutDisplayFunc(myDraw);glutMainLoop();return0;}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功