计算机图形学实验报告
(34页)
本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!
14.90 积分
计算机图形学实验报告计 算 机 图 形 学课程实验报告姓名:学号:计算机图形学实验报告目 录DDA算法绘制直线实验一实验一 直线的DDA算法一、【实验目的】1.掌握DDA算法的基本原理。2.掌握DDA直线扫描转换算法。3.深入了解直线扫描转换的编程思想。二、【实验内容】1.利用DDA的算法原理,编程实现对直线的扫描转换。2.加强对DDA算法的理解和掌握。三、【测试数据及其结果】四、【实验源代码】#include#include#include#includeGLsizei winWidth=500;GLsizei winHeight=500;void Initial(void){ glClearColor(1.0f,1.0f,1.0f,1.0f); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,200.0,0.0,150.0);}void DDALine(int x0,int y0,int x1,int y1){ glColor3f(1.0,0.0,0.0); int dx,dy,epsl,k; float x,y,xIncre,yIncre; dx=x1-x0; dy=y1-y0; x=x0; y=y0; if(abs(dx)>abs(dy)) epsl=abs(dx); else epsl=abs(dy); xIncre=(float)dx/(float)epsl; yIncre=(float)dy/(float)epsl; for(k=0;k<=epsl;k++) { glPointSize(3); glBegin(GL_POINTS); glVertex2i(int(x+0.5),(int)(y+0.5)); glEnd(); x+=xIncre; y+=yIncre; }}void Display(void){ glClear(GL_COLOR_BUFFER_BIT); DDALine(100,100,200,180); glFlush();}void winReshapeFcn(GLint newWidth, GLint newHeight){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, GLdouble(newWidth), 0.0, GLdouble(newHeight)); glClear(GL_COLOR_BUFFER_BIT); winWidth=newWidth; winHeight=newHeight;}int main(int argc,char*argv[]){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400,300); glutInitWindowPosition(100,120); glutCre-省略部分-ion[]={-3.0f,-3.0f,3.0f,1.0f}; GLfloat spot_direction[]={1.0f,1.0f,-1.0f}; glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient); glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse); glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular); glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);glLightfv(GL_LIGHT0,GL_DIFFUSE,light0_diffuse);glLightfv(GL_LIGHT0,GL_POSITION,light0_position);glLightfv(GL_LIGHT1,GL_AMBIENT,light1_diffuse);glLightfv(GL_LIGHT1,GL_DIFFUSE,light1_diffuse);glLightfv(GL_LIGHT1,GL_SPECULAR,light1_specular);glLightfv(GL_LIGHT1,GL_POSITION,light1_position);glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,30.0);glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,spot_direction);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_LIGHT1);glEnable(GL_DEPTH_TEST);glClearColor(1.0f,1.0f,1.0f,1.0f);}void ChangSize(GLsizei w,GLsizei h){ if(h==0) h=1; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glOrtho(-5.5f,5.5f,-5.5f*h/w,5.5f*h/w,-10.0f,10.0f); else glOrtho(-5.5f*w/h,5.5f*w/h,-5.5f,5.5f,-10.0f,10.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}void Display(void){ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslated(-3.0f,-3.0f,3.0f); glPopMatrix(); glutSolidSphere(2.0f,50,50); glFlush();}void main(void){ glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("多光源球"); glutDisplayFunc(Display); glutReshapeFunc(ChangSize); Initial(); glutMainLoop();} 关 键 词: 实验 报告 图形 计算机
天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。