Jason
Jason

Reputation: 21

Failed to execute 'uniformMatrix4fv'

I'm very new to OpenGL and Javascript so I'm not sure what exactly is wrong. I am making a program that rotates a shape along all three axes x,y and z. I am trying to multiply my position vectors with a rotation matrix but I'm getting this error:

Uncaught TypeError: Failed to execute 'uniformMatrix4fv' on 'WebGLRenderingContext': No function was found that matched the signature provided.

Here is my vertex shader, I've shortened it to hide the unnecessary code which already works so I can highlight where I am having the problem. I have the multiplication here also:

attribute vec2 pos;
uniform mat4 rotation;

void main(){

 gl_Position = rotation*vec4(vec3(pos,0),1);

 gl_Position.x = pos.x*cos(shift) - pos.y*sin(shift);
 gl_Position.y = pos.y*cos(shift)  + pos.x*sin(shift);
 gl_Position.z =0.0;
 gl_Position.w =1.0;
}

This is one of the rotation functions, I am doing one for each axis. The rotation matrix which is 4x4 looks like this:

function xAxis(angle){
var c = Math.cos(angle);
var s = Math.sin(angle);

return[
1,0,0,0,
0,c,-s,0,
0,s,c,0,
0,0,0,1
];
}

But when I try to use this command inside the draw function I get an error

gl.uniformMatrix4fv(rotationLocation, false, rotation);

So my question is how do I fix this error?

EDIT: I should add that I am using a Javascript file as well as an HTML file. All the important code, so the vertex shader, fragment shader etc, is inside the Javascript file.

EDIT 2: I should also add that the program worked fine before I added these lines of code.

EDIT 3: Here's a Link to my Javascript code I converted it to a text file for easier reading

Upvotes: 1

Views: 5163

Answers (1)

Jason
Jason

Reputation: 21

Ok so I figured out the problem. I accidentally created 2 xAxis() functions in my program. The way I designed it, the first one would identify which axis to rotate around, and the second one would do the matrix multiplication. I mistakenly gave them the same name which gave me the error, when I renamed one to xAxis_rotate() my problem got solved.

Upvotes: 1

Related Questions