P
P
Pavel Shvedov2015-01-19 17:17:12
Java
Pavel Shvedov, 2015-01-19 17:17:12

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();
        }

    }

Everything is drawn in the right places, the camera rotates and flies between them. But the light seems to be chasing the center of the camera's view, and constantly follows it. In l.updateLight(); the following happens:
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);
    }

In the m.draw() method, drawing takes place according to the usual principle glBegin(GL_QUADS); .(here are all the points and texture coordinates of the cube).. glEnd();
Where do I update the position of the light so that it is not affected by the gluLookAt() of the camera. The position vector in the class describing Light is set once in the constructor and does not change. How to fix a jamb?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question