I've been piecing together a basic game engine using jogl and have hit a pretty big road bump when it comes to accessing and/or updating uniform variables in my shader code.
Here is how I am allocating the Matrix and associated Buffer:
protected float[] test_matrix = {
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
protected int matrix_size = test_matrix.length;
FloatBuffer matrix_buffer = Buffers.newDirectFloatBuffer(test_matrix, 0, matrix_size);
Here is the code in question:
shaderProgram = gl.glCreateProgram();
gl.glAttachShader(shaderProgram, vertShader);
gl.glAttachShader(shaderProgram, fragShader);
pmvmatrix = new PMVMatrix();
transmatrix_location = gl.glGetUniformLocation(shaderProgram, "transformationMatrix");
gl.glUniformMatrix4fv(transmatrix_location, 400, false, matrix_buffer);
pmvmatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmvmatrix.glLoadIdentity();
gl.glBindAttribLocation(shaderProgram, 0, "position");
gl.glBindAttribLocation(shaderProgram, 1, "color");
gl.glLinkProgram(shaderProgram);
And here is my vertex shader:
#version 400 core
in vec3 position;
out vec3 color;
uniform mat4 transformationMatrix;
void main(void){
gl_Position = transformationMatrix * vec4(position,1.0);
color = vec3(position.x+0.5,1.0,position.y+0.5);
}
The shaders are compiling successfully and if I remove the "transformationMatrix *" in my vertex shader, the object renders properly.
Is my matrix just being passed as a 1X16 matrix rather than a 4X4? Am I using the glUniformMatrix4fv function properly?
transmatrix_location
less than zero? – genpfault