资源描述:
《计算机图形学OpenGL(会生长的树).doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、计算机图形学OpenGL——会生长的树源程序:#include"stdafx.h"#include#includeGLfloata=28.0,b=5.0,c=23.0,d=3.0,e=-2.0,f=2.0,p=1.2;voiddisplay(void){glClear(GL_COLOR_BUFFER_BIT);glColor3f(0.0,1.0,0.0);glBegin(GL_TRIANGLES);glVertex2i(0,a*p);glVertex2i(-b*p,c*p);glVertex2i(b*p,c*
2、p);glVertex2i(0,(a-d)*p);glVertex2i((-b-d)*p,(c-2*d)*p);glVertex2i((b+d)*p,(c-2*d)*p);glVertex2i(0,(a-2*d)*p);glVertex2i((-b-2*d)*p,(c-4*d)*p);glVertex2i((b+2*d)*p,(c-4*d)*p);glEnd();glColor3f(0.0,1.0,0.0);glBegin(GL_QUAD_STRIP);glVertex2i(e*p,(c-4*d)*p);glVertex2i(e*p,0);glV
3、ertex2i(f*p,(c-4*d)*p);glVertex2i(f*p,0);glEnd();glFlush();}voididle(void){p=(p<20)?p+0.002:p;glutPostRedisplay();}voidmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE
4、GLUT_RGB);glutInitWindowSize(400,300);glutInitWindowPosition(200,100);glutCreat
5、eWindow("会á生Θ?长¤的?树骸?);glClearColor(0.0,0.0,0.0,0.0);gluOrtho2D(-400.0,400.0,0.0,600.0);glutDisplayFunc(display);glutIdleFunc(idle);glutMainLoop();}