Currently I am trying to illuminate an object with a light source and change the color of the object based on GL_COLOR_MATERIAL. For some reason, I am only able to see ONE light source being projected on to the model. I've tried various different positions and combination of light sources and I have noticed only GL_LIGHT0 functions.
I've also tried different combination of ambient/diffuse/materials with no success.
static const GLfloat ambient[4] = {0.1f, 0.1f, 0.1f开发者_Python百科, 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);
}
Any help would be greatly appreciated!
There are several parameters (eg GL_DIFFUSE
) which default to 0,0,0,0
for GL_LIGHT1
.. GL_LIGHT7
but something else (eg 1,1,1,1
) for GL_LIGHT0
. I don't know which one you've missed, but I bet you're relying on a default for both lights and it's "off" for GL_LIGHT1
.
精彩评论