已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
使用openGl画直线(DDA算法)、画圆、椭圆(Bresenham算法)#include#include #include /* initialization: */ void myinit(void) /* attributes */ glClearColor(1.0, 1.0, 1.0, 0.0); /* white background */ glColor3f(1.0, 0.0, 0.0); /* draw in red */ /* set up viewing: */ /* 500 x 500 window with origin lower left */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 500.0, 0.0, 500.0); glMatrixMode(GL_MODELVIEW); void plot_circle_points(int xc,int yc,int x,int y)/画圆 glBegin(GL_POINTS); glVertex3f(xc+x,yc+y,0); glVertex3f(xc-x,yc+y,0); glVertex3f(xc+x,yc-y,0); glVertex3f(xc-x,yc-y,0); glVertex3f(xc+y,yc+x,0); glVertex3f(xc-y,yc+x,0); glVertex3f(xc+y,yc-x,0); glVertex3f(xc-y,yc-x,0); glEnd();void drawcircle(int xc,int yc,int radius) int x,y,p; x=0; y=radius; p=3-2*radius; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); while(xy) plot_circle_points(xc,yc,x,y); if(p0) p=p+4*x+6; else p=p+4*(x-y)+10; y-=1; x+=1; if(x=y) plot_circle_points(xc,yc,x,y); void putpixel(int xc,int yc,int x,int y)/画椭圆glBegin(GL_POINTS); glVertex3f(xc+x,yc+y,0); glEnd();void drawEllipse(int xc,int yc,int a,int b) int x,y;float d1,d2;x=0;y=b;d1=b*b+a*a*(-b+0.25);putpixel(xc,yc,x,y);putpixel(xc,yc,-x,-y);putpixel(xc,yc,-x,y);putpixel(xc,yc,x,-y);while(b*b*(x+1)a*a*(y-0.5)if(d10)if(d2abs(dy) steps=abs(dx); else steps=abs(dy); delta_x=(GLfloat)dx/(GLfloat)steps; delta_y=(GLfloat)dy/(GLfloat)steps; x=xa; y=ya; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); glVertex3f(x,y,0); for(int k=1;k=steps;k+) x+=delta_x; y+=delta_y; glBegin(GL_POINTS); glVertex3f(x,y,0); glEnd(); /* the display callback: */ void display1() /画圆 glClear(GL_COLOR_BUFFER_BIT); /*clear the window */ /*-*/ /* viewport stuff */ /*-*/ /* set up a viewport in the screen window */ /* args to glViewport are left, bottom, width, height */ glViewport(0, 0, 500, 500); /* NB: default viewport has same coords as in myinit, */ /* so this could be omitted: */dda_line(20,20,420,350); /* and flush that buffer to the screen */ glFlush(); void display2() /画圆 glClear(GL_COLOR_BUFFER_BIT); /*clear the window */ /*-*/ /* viewport stuff */ /*-*/ /* set up a viewport in the screen window */ /* args to glViewport are left, bottom, width, height */ glViewport(0, 0, 500, 500); /* NB: default viewport has same coords as in myinit, */ /* so this could be omitted: */drawcircle(250,250,100); /* and flush that buffer to the screen */ glFlush(); void display3() /画圆 glClear(GL_COLOR_BUFFER_BIT); /*clear the window */ /*-*/ /* viewport stuff */ /*-*/ /* set up a viewport in the screen window */ /* args to glViewport are left, bottom, width, height */ glViewport(0, 0, 500, 500); /* NB: default viewport has same coords as in myinit, */ /* so this could be omitted: */drawEllipse(250,250,60,40); /* and flush that buffer to the screen */ glFlush(); int main(int argc, char* argv) /* Standard GLUT initialization */ glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */ glutInitWindowSize(500,500); /* 500 x 500 pixel window */ glutInitWindowPosition(0,0); /* place window top left on display */cout*endl;cout* 请选择如下操作: *endl;cout* 1.用DDA画线 *endl;cout* 2.用Bresenham算法画圆 *endl;cout* 3.用Bresenham算法画椭圆 *endl;cout*endl;coutchoice;switch(choice)case 1: glutCreateWindow(Bresenham circile); /* window title */ glutDisplayFunc(display1); /* display callback invoked when window opened */ myinit(); /* set attributes */ glutMainLoop(); /* enter event loop */break;case 2: glutCreateWindow(Digital Differential Analyser Line); /* window title */ glutDisplayFunc(display2); /* display callback invoked when window opened */ myinit(); /* set attributes */ glutMainLoop(); /* enter event loop */break;case 3:glutCreateWindow(MidBresenhamEllipse
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 家电能效认证咨询创新创业项目商业计划书
- 复古风床头装饰创新创业项目商业计划书
- 封口智能选型工具创新创业项目商业计划书
- 指纹与面部识别融合方案创新创业项目商业计划书
- 心理健康放松音乐与冥想课程创新创业项目商业计划书
- (2025年)传染病及食源性疾病防治知识考核试题(答案)
- 人美版(2024)小学二年级上册美术第一单元 温馨的情感(第1~3课)教案
- 南大版八年级全一册心理健康教育第八课 超越嫉妒 教案
- 2025年湛江辅警协警招聘考试备考题库含答案详解(精练)
- 2025年鄂州辅警协警招聘考试真题附答案详解(黄金题型)
- 《森林报·冬》读书分享
- 5年(2021-2025)高考1年模拟数学真题分类汇编专题06 数列(天津专用)(解析版)
- 千与千寻具体讲解
- 《油气储存企业安全风险评估细则(2025年修订)》解读
- 2024中国肥胖症内分泌诊疗指南第2版解读课件
- 山东省德州市2024-2025学年高一上学期期中考试化学试卷(含答案)
- GB/T 3672.1-2025橡胶制品的公差第1部分:尺寸公差
- 人教版(2024)八年级上册英语Unit 1 Happy Holiday 教案(共6课时)
- 《南京大屠杀》课件
- 多彩食物的课件欣赏
- 农机消防安全知识培训课件
评论
0/150
提交评论