GL_LIGHT仅创建一个光源

时间:2011-02-28 21:56:39

标签: c++ opengl

目前我正在尝试使用光源照亮对象,并根据GL_COLOR_MATERIAL更改对象的颜色。出于某种原因,我只能看到一个光源被投射到模型上。我尝试了各种不同的位置和光源组合,我只注意到GL_LIGHT0功能。

我也尝试了环境/漫反射/材质的不同组合,但没有成功。

static const GLfloat ambient[4] = {0.1f, 0.1f, 0.1f, 1.0f};
static const GLfloat diffuse[4] = {0.5f, 1.0f, 1.0f, 1.0f};
static const GLfloat position0[4] = {0.0f, 0.0f, 20.0f, 0.0f};
static const GLfloat position1[4] = {0.0f, 0.0f, -20.0f, 0.0f};
static const GLfloat front_mat_shininess[1] = {60.0f};
static const GLfloat front_mat_specular[4] = {0.2f, 0.2f, 0.2f, 1.0f};
static const GLfloat front_mat_diffuse[4] = {0.5f, 0.28f, 0.38f, 1.0f};

static const GLfloat lmodel_ambient[4] = {1.0f, 1.0f, 1.0f, 1.0f};
static const GLfloat lmodel_twoside[1] = {GL_FALSE};

glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);

///Enable lighting if item is a solid model
if(wireFlag == 1)
{
    glEnable(GL_LIGHTING);
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
    glLightfv(GL_LIGHT0, GL_POSITION, position0);
    glEnable(GL_LIGHT0);

    glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
    glLightfv(GL_LIGHT1, GL_POSITION, position1);
    glEnable(GL_LIGHT1);

    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);


    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_mat_shininess);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_mat_specular);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, front_mat_diffuse);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_COLOR_MATERIAL);
}

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:6)

GL_DIFFUSE 0,0,0,0有几个参数(例如GL_LIGHT1)默认为GL_LIGHT7,但1,1,1,1有其他参数(例如GL_LIGHT0) 1}}。我不知道你错过了哪一个,但我敢打赌你依赖于两个灯的默认值而且GL_LIGHT1的“关闭”。