Answer the question
In order to leave comments, you need to log in
How to fix the light source on the stage?
All the good time of the day. Actually, the question from the title is clear, but I'll still write a little in more detail.
There is a simple Java program using LWJGL 2. Based on various tutorials, I implemented the rendering of many textured cubes. The cubes are rendered without using glTranslate(). Each cube instance has a Vector3f position vector that points to the center of the cube, and all vertices are drawn relative to it.
Implemented an FPS camera using gluLookAt(); everything runs and looks good. Added lighting and then strange things began. The render function is the following:
private void render() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
lcamera.setView();
for(Cube m: cubes) {
m.draw();
}
for(Light l: lights) {
l.updateLight();
}
}
public void updateLight() {
FloatBuffer tmpBuffer = BufferUtils.createFloatBuffer(4);
tmpBuffer.put(position); tmpBuffer.flip();
glLight(lightNum, GL_POSITION, tmpBuffer);
tmpBuffer = BufferUtils.createFloatBuffer(4);
tmpBuffer.put(spotDirection); tmpBuffer.flip();
glLight(lightNum, GL_SPOT_DIRECTION, tmpBuffer);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question