聚焦问题 OpenGL

Spotlight issue OpenGL

我在 OpenGL 库中遇到聚光灯问题。场景是黑色的,如果 GL_SPOT_CUTOFF 小于 125,则看不到光。我认为这个问题与光源的方向有关,但我已经尝试了很多关于聚光灯位置和方向的选项。这是我的代码:

const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };

glPushMatrix();
glLoadIdentity();
GLfloat spot_direction[] = { 0.0, -1.0, 0.0 ,0.0};
GLfloat spot_position[] = { 1.0,1.0,0.0,1.0 };
glLightfv(GL_LIGHT1, GL_POSITION, spot_position);
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);

glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 60);
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 100);
glPopMatrix();

glEnable(GL_LIGHT1);

已解决。问题是 GL_SPOT_EXPONENT 系数太高(光线过于集中)和光流的方向。