辅助镜面颜色:在纹理贴图之后再应用镜面亮点。(通过加法而不是乘法。)
调用
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
想要恢复则调用
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
void SetupRC() { glClearColor(fLowLight[0],fLowLight[1],fLowLight[2],fLowLight[3]); glClearStencil(0); glStencilFunc(GL_EQUAL,0x0,0x1); glStencilOp(GL_INCR,GL_INCR,GL_INCR); glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_MULTISAMPLE_ARB); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);//<-------就是这一句啦 glLightModelfv(GL_LIGHT_MODEL_AMBIENT,fNoLight); glLightfv(GL_LIGHT0,GL_AMBIENT,fLowLight); glLightfv(GL_LIGHT0,GL_DIFFUSE,fBrightLight); glLightfv(GL_LIGHT0,GL_SPECULAR,fBrightLight); m3dGetPlaneEquation(mPlaneEquation,vPlanePoints[0],vPlanePoints[1],vPlanePoints[2]); m3dMakePlanarShadowMatrix(mShadowEquation,mPlaneEquation,fLightPos); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); glMaterialfv(GL_FRONT,GL_SPECULAR,fBrightLight); glMateriali(GL_FRONT,GL_SHININESS,128); for (GLint i=0;i<nNumSpheres;i++) { Sphere[i].SetOrigin(((float)((rand() % 400) - 200) * 0.1f), 0.0, (float)((rand() % 400) - 200) * 0.1f); } glEnable(GL_TEXTURE_2D); glGenTextures(nNumTexture,unTexturesObj); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); for (GLint i=0;i<nNumTexture;i++) { GLbyte *pBytes; GLint iWidth, iHeight, iComponents; GLenum eFormat; glBindTexture(GL_TEXTURE_2D,unTexturesObj[i]); pBytes=gltLoadTGA(szTextures[i],&iWidth,&iHeight,&iComponents,&eFormat); gluBuild2DMipmaps(GL_TEXTURE_2D,iComponents,iWidth,iHeight,eFormat,GL_UNSIGNED_BYTE,pBytes); free(pBytes); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); } }