资源描述:
《试验二计算机图形学中点画线法.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、中点画线法#include#include#include#include#include//opengl32.libglu32.libglaux.libintx1,y1,x2,y2;voidInitGL(void){auxInitDisplayMode(AUX_SINGLE
2、AUX_RGBA);auxInitPosition(0,0,640,480);auxInitWindow("FirstA
3、uxOpenGLDemo");glClearColor(0.6,0.6,0.6,0.0);glClear(GL_COLOR_BUFFER_BIT);}voidMidpointLine(intx1,inty1,intx2,inty2){inti,x,y;floatdx,dy,d,k;dx=x2-x1;dy=y2-y1;k=dy/dx;if(k<=1){d=0.5-k;x=x1;y=y1;glVertex2i(x1,y1);for(i=1;i<=dx;i++){glBegin(GL_POINTS);
4、glVertex2i(x,y);x++;if(d<0){y++;d=d+1-k;}elsed=d-k;Sleep(10);glEnd();//结束绘制glFlush();//进行刷新}}if(k>1){d=1-0.5*k;x=x1;y=y1;glVertex2i(x1,y1);for(i=1;i<=dy;i++){glBegin(GL_POINTS);glVertex2i(x,y);y++;if(d<0){x++;d=d+1;}elsed=d-k+1;Sleep(10);glEnd();//结束
5、绘制glFlush();//进行刷新}}}voidCALLBACKDraw(void){//glBegin(GL_POINTS);MidpointLine(x1,y1,x2,y2);//glEnd();//结束绘制//glFlush();//进行刷新}voidmain(void){printf("pleaseinputthestartpoint(x1,y1):");scanf("%d,%d",&x1,&y1);printf("pleaseinputthestartpoint(x2,y2):");
6、scanf("%d,%d",&x2,&y2);InitGL();//初始化auxMainLoop(Draw);//进行绘制}