好文档 - 专业文书写作范文服务资料分享网站

计算机图形学实验报告

天下 分享 时间: 加入收藏 我要投稿 点赞

NURBS曲面和Bezier曲面 实验七 DrawPoints(); glutSwapBuffers(); }

void ChangeSize(int w,int h) { if(h==0)h=1; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLdouble)w/(GLdouble)h,1.0,40.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f,0.0f,-20.0f); }

int main(int argc,char*argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutCreateWindow(\曲面\ glutReshapeFunc(ChangeSize); glutDisplayFunc(ReDraw); glutMainLoop(); return 0; }

两点光源在球体上的效果 实验八 实验八 两点光源在球体上的效果

一、【实验目的】

1.掌握漫反射光、镜面反射光和聚光源的含义。 2.掌握opengl中不同点光源的设置。

二、【实验内容】

1.设置两个光源,一个是漫反射的蓝色点光源,另一个是红色聚光光源,他们都照在一个球体上,产生亮斑。 2.调用opengl中的函数指定当前设定的材质应用于物体表面的哪个面,从而使光照下产生特殊的效果。

三、【测试数据及其结果】

四、【实验源代码】

#include #include

两点光源在球体上的效果 void Initial(void) { GLfloat mat_ambient[]={0.2f,0.2f,0.2f,1.0f}; GLfloat mat_diffuse[]={0.8f,0.8f,0.8f,1.0f}; GLfloat mat_specular[]={1.0f,1.0f,1.0f,1.0f}; GLfloat mat_shininess[]={50.0f}; GLfloat light0_diffuse[]={0.0f,0.0f,1.0f,1.0f}; GLfloat light0_position[]={1.0f,1.0f,1.0f,0.0f}; GLfloat light1_ambient[]={0.2f,0.2f,0.2f,1.0f}; GLfloat light1_diffuse[]={1.0f,0.0f,0.0f,1.0f}; GLfloat light1_specular[]={1.0f,0.6f,0.6f,1.0f}; GLfloat light1_position[]={-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();

实验八

计算机图形学实验报告

NURBS曲面和Bezier曲面实验七DrawPoints();glutSwapBuffers();}voidChangeSize(intw,inth){if(h==0)h=1;glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspecti
推荐度:
点击下载文档文档为doc格式
30xid2saoe38gut0xsx29kcek7hlwh013zo
领取福利

微信扫码领取福利

微信扫码分享