我使用的是opengl 2.1版,glsl 120,lwjgl 3.每当我调用GL20.glUniformMatrix4fv()时,它都不会被着色器程序识别。调试完所有着色器和程序后,不会返回任何错误。GLSL 120顶点着色器显示比着色器程序更少的活动制服
将立方体绘制到窗口上(因为没有投影它显示为四边形)。 着色器程序,没有错误编译和作品:
#version 120
attribute vec3 position;
uniform mat4 modelView;
uniform mat4 proj;
void main()
{
gl_Position = vec4(position, 1.0); // See how we directly give a vec3 to vec4's constructor
}
没有被吸引到窗口。 着色器程序没有错误的编译,但没有显示在屏幕上:
#version 120
attribute vec3 position;
uniform mat4 modelView;
uniform mat4 proj;
void main()
{
gl_Position = proj * vec4(position, 1.0); // See how we directly give a vec3 to vec4's constructor
}
片段着色器:
#version 120
void main()
{
gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0);
}
程序总是链接和编译,但统一的凸出不起作用。
这是统一的数据被发送代码:
GL20.glUseProgram(shaderProgram);
int model = GL20.glGetAttribLocation(shaderProgram, "modelView");//used get attrib here instead of GL20.glGetUniformLocation();
Matrix4f modelView = new Matrix4f().translate(.5f, .5f, .5f);
GL20.glUniformMatrix4fv(model, false, modelView.get(buffer));
int proj = GL20.glGetAttribLocation(shaderProgram, "proj");//and here
Matrix4f projection = new Matrix4f().
perspective((float)Math.toRadians(45), 1.0f, 0.1f, 100f).
lookAt(0.0f, 0.0f, -3.0f, //eye
0.0f, 0.0f, 0.0f, //center
0.0f, 1.0f, 0.0f);//up
GL20.glUniformMatrix4fv(proj, false, projection.get(buffer));
//draw container
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO);
GL11.glDrawArrays(GL_TRIANGLES, 0, 36);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
{}更新把gluseprogram调用之前gluniformmatrix4fv 还是什么都没有被吸引到屏幕上。当标识矩阵被发送到proj然后乘以vec4立方体消失。
检查:
GL20.glGetShaderiv(vertexID, GL20.GL_ACTIVE_UNIFORMS, success);
在顶点着色器返回零 同时检查:
GL20.glGetProgramiv(shaderID, GL20.GL_ACTIVE_UNIFORMS, success);
在着色器程序返回1或2时凸出和MODELVIEW在主方法被使用。
[解决更新] 正在使用get attrib位置而不是统一的位置。
'projection.get'做什么? [lwjgl Matrix4f](http://legacy.lwjgl.org/javadoc/org/lwjgl/util/vector/Matrix4f.html)类不提供此功能。 – BDL
LWJGL版本3摆脱了所有的矩阵运算。我正在使用JOML,Java opengl数学库。每当你在矩阵上调用get方法时,它将返回该矩阵中的所有内容并将其放入缓冲区,这是opengl需要的大部分函数的数据结构。 –
缓冲器是一个16浮点缓冲器吗?你应该真的创建一个MVCE,否则我们可以猜测问题出在哪里。 – BDL