如何打开和关闭场景中的环境光

  • 本文关键字:环境光 何打开 opengl
  • 更新时间 :
  • 英文 :


在我的场景中,环境光的值为:

GLfloat global_ambient[] = {0.4, 0.4, 0.4};

在我的initGL中,我正在启用它:

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);

我想当我按下"s"键时切换灯光。我知道如何切换灯光,我的问题是有没有像glEnagle和glDisable这样的方法来处理环境光?

我自己想的。在我的KeyResponder方法中,当用户按下s键时,这就是我正在做的:

if (key == 's'){
    if (isAmbientOn){
        //if it is true turn the ambient off by setting the R,G,B values to 0
        global_ambient[0] = 0;
        global_ambient[1] = 0;
        global_ambient[2] = 0;
        isAmbientOn = false;
    }
    else{
        //if it is false tuen the ambient on by setting it to a value - 0.4
        global_ambient[0] = 0.4;
        global_ambient[1] = 0.4;
        global_ambient[2] = 0.4;
        isAmbientOn = true;
    }
}

在我的DrawScene方法中:

void CDrawModel::myDrawGLScene(GLvoid)      // Here's Where We Do All The Drawing{
//set up the ambient light in myDrawGLScene so we can switch it on and off on 's' key press...
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
{

最新更新