《计算机图形学》6 OpenGL中的明暗处理-英文教学课件(非AI生成).ppt
6.8SpecificationofmaterialinOpenGL
OpenGL中的材质属性
(用颜色指定代替材料属性指定)通常当启用光照进行明暗处理后,原来的glColor*()命令失去原有的作用如果调用了glEnable(GL_COLOR_MATERIAL),那么就会使光照模型中的几种光根据glColor*()中的指定确定颜色,专门改变材质某种光照下的颜色属性分量:voidglColorMaterial(GLenumface,GLenummode);其中face的取值GL_FRONT,GL_BACK与GL_FRONT_AND_BACK(默认值)mode的取值为GL_EMISSION,GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR与GL_AMBIENT_AND_DIFFUSE(默认值)6.8SpecificationofmaterialinOpenGL
OpenGL中的材质属性
(颜色材料模式例子)不需要使用glColorMaterial()时,确保禁用glEnable(GL_COLOR_MATERIAL);glColorMaterial(GL_FRONT,GL_DIFFUSE);/*nowglColor*changesdiffusereflection*/glColor3f(0.2,0.5,0.8);/*drawsomeobjectshere*/glColorMaterial(GL_FRONT,GL_SPECULAR);/*glColor*nolongerchangesdiffusereflection*//*nowglColor*changesspecularreflection*/glColor3f(0.9,0.0,0.2);/*drawotherobjectshere*/glDisable(GL_COLOR_MATERIAL);6.8SpecificationofmaterialinOpenGL
OpenGL中的材质属性
(Efficiency效率-1)Becausematerialpropertiesarepartofthestate,ifwechangematerialsformanysurfaces,wecanaffectperformance由于材料属性为状态的一部分,因此如果对许多表面采用大量的不同材料,那么系统的性能就会大打折扣使用glColorMaterial(),只改变单独一种材质的颜色分量,这种方法比glMaterial更加有效6.8SpecificationofmaterialinOpenGL
OpenGL中的材质属性
(Efficiency效率-2)Wecanmakethecodecleanerbydefiningamaterialstructureandsettingallmaterialsduringinitialization可以通过定义一个材料结构,利用它在初始化时设置所有材料,从而净化代码程序员编程效率Wecanthenselectamaterialbyapointer这样可以通过指针选择一种材料typedefstructmaterialStruct{GLfloatambient[4];GLfloatdiffuse[4];GLfloatspecular[4];GLfloatshineness;}MaterialStruct;6.8SpecificationofmaterialinOpenGL
OpenGL中的材质属性
(Transparency透明效果)MaterialpropertiesarespecifiedasRGBAvalues??材料属性是利用RGBA值指定的TheAvaluecanbeusedtomakethesurfacetranslucentA值用来使表面透明ThedefaultisthatallsurfacesareopaqueregardlessofA默认状态下不管A的值是多少,所有表面都是不透明的Laterwewillenableblendingandusethisfeature后面我们会讲到如何激活融合(blending)功能以及这种功能的应用PolygonalShadingi