Hello, I need help. I have a rather complicated problem with loading uniform variables to my vertex shader.
I had a project in LWJGL version 2 and it worked. Now I updated to LWJGL 3 and changed everything to make it work again. My window doesn't show any models now.
I tested this:
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(-0.5f + pos1, 0.5f);
GL11.glVertex2f(0.5f, 0.5f);
GL11.glVertex2f(0.5f, -0.5f);
GL11.glVertex2f(-0.5f, -0.5f);
GL11.glEnd();
and it shows a quad, but when i activate my shader before I draw, it doesn't work anymore. I don't want to post all my code, but I can show the relevant stuff and why it is causing the issue.
When I remove all the matrices from my vertex shader code (transformation, projection, view). It shows the quad again:
gl_Position = vec4(position, 1.0);
This works.
I can also create a matrix in my shader and use it, so this works, too:
mat4 test;
test[0] = vec4(1.0,0.0,0.0,0.0);
test[1] = vec4(0.0,1.0,0.0,0.0);
test[2] = vec4(0.0,0.0,1.0,0.0);
test[3] = vec4(0.0,0.0,0.0,1.0);
gl_Position = test * vec4(position, 1.0);
But uniform matrices don't (and I tested floats, they work):
uniform mat4 test;
void main(void) {
gl_Position = test * vec4(position, 1.0);
}
And my code to load it:
private static FloatBuffer matrixBuffer = MemoryUtil.memAllocFloat(16);
protected void loadMatrix(int location, Matrix4f matrix) {
matrix.get(matrixBuffer);
matrixBuffer.flip();
GL20.glUniformMatrix4fv(location, false, matrixBuffer);
//somewhere else:
loadMatrix(location_test, new Matrix4f());
}
The "new Matrix4f()" creates a matrix with the same values I created manually in my shader before, but my quad disappears again. And as I said, loading floats worked and I didn't misspell any of the variable names.
Anyone have an idea?