lory
lory

Reputation: 29

Matrix error LWJGL

I made this little game engine but when I setup matrix in shader GLSL position got annulled by it and any image goes displayed... Here GLSL program:

            "#version 450 core\n" +
                "layout(location=0) in vec2 in_Position;\n" +
                "layout(location=0) uniform mat4 uni_Model;\n" +
                "void main() {\n" +
                "   gl_Position = uni_Model * vec4(in_Position, 0.0f, 1.0f);\n" +
                "}";

Here's my matrix:

            Matrix4f matrix = new Matrix4f();
        matrix.translate(new Vector3f(0.0f, 0.0f, 0.0f)); // I know it don't translate anything, it was just a test
        matrix.scale(new Vector3f(1.0f, 1.0f, 1.0f)); // I know it don't scale anything, " " "
        FloatBuffer modelBuffer = FloatBuffer.allocate(16);
        matrix.store(modelBuffer);

        glUniformMatrix4fv(0, false, modelBuffer); // 0 is the location of the uniform

If I remove matrix from GLSL and from Java Code the program works fine, it means that the Matrix has null values and cancels gl_Position value. Finally here's my output: https://gyazo.com/99bddae6e7dbf8165940e15632d41e83 I clear screen of blue color each frame.

Upvotes: 1

Views: 154

Answers (1)

lory
lory

Reputation: 29

I solved! The problem was I forgot to call modelBuffer.flip() but only replacing it, it gave me a native error. So I found another issue in FloatBuffer initliazation: I replaced FloatBuffer.allocate(16) with BufferUtils.createFloatBuffer(16) and now all works fine :)

Upvotes: 1

Related Questions