1
我做了这个小游戏引擎,但是当着色器GLSL位置我设置矩阵得到了由它废止任何图像会显示... 这里GLSL程序:矩阵错误LWJGL
"#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" +
"}";
这里是我的矩阵:
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
如果我从GLSL和Java代码中删除矩阵,程序运行良好,这意味着Matrix有空值并取消gl_Position值。 终于这是我的输出: https://gyazo.com/99bddae6e7dbf8165940e15632d41e83 我清除每一帧蓝色的画面。
你知道GL_POSITION希望接收“标准化设备坐标”?因此,除非in_Position给出标准化的设备坐标,否则单位矩阵不会进行所需的转换。 – St0fF
@ St0fF:他说他的代码在没有矩阵的情况下工作。所以传递一个身份矩阵不应该影响任何东西。 –
@NicolBolas是对的 – lory