我一直致力于使用 LWJGL 加载、渲染和照明 3D 模型。它主要工作,但目前照明存在问题,我认为这是照明正常但我无法修复它。这是问题的图片;
照明代码:
public class Light {
private Vector4f position;
public Light(Vector3f position)
{
this.position = new Vector4f(position.x, position.y, position.z, 1);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightModel(GL_LIGHT_MODEL_AMBIENT, getFlipedFloatBuffer(new Vector4f(0.05f, 0.05f, 0.05f, 1)));
glLight(GL_LIGHT0, GL_POSITION, getFlipedFloatBuffer(this.position));
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
}
private FloatBuffer getFlipedFloatBuffer(Vector4f values)
{
return (FloatBuffer)BufferUtils.createFloatBuffer(4).put(new float[]{values.x, values.y, values.z, values.w}).flip();
}
public void update() {
glLight(GL_LIGHT0, GL_POSITION, getFlipedFloatBuffer(this.position));
}
}