【发布时间】:2016-01-26 21:46:10
【问题描述】:
我制作了这个小游戏引擎,但是当我在着色器 GLSL 位置设置矩阵时,它被它取消并且任何图像都会显示... 这里是 GLSL 程序:
"#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 代码中删除矩阵,程序工作正常,这意味着矩阵有空值并取消 gl_Position 值。 最后这是我的输出: https://gyazo.com/99bddae6e7dbf8165940e15632d41e83 我每帧清除蓝色屏幕。
【问题讨论】:
-
你知道 gl_Position 想要接收“标准化设备坐标”吗?因此,除非 in_Position 给出标准化的设备坐标,否则单位矩阵不会进行所需的转换。
-
@St0fF:他说他的代码没有矩阵也能工作。所以传递一个单位矩阵应该不会影响任何事情。
-
@NicolBolas 是对的
标签: matrix glsl lwjgl opengl-4