I am new to OpenGL and I seem to be experiencing some difficulties. I wrote a simple shader in GLSL that needs to transform vertices using shared matrices, allowing simple skeletal animation. Each vertex has a maximum of two bone effects (stored as the x and y components of Vec2), indices and corresponding weights that are associated with the array of transformation matrices and are listed as “Attribute Variables” in my shader, and then set using the glVertexAttribPointer function.
Here, where the problem arises ... I managed to correctly set the array of "Uniform Variable" matrices, when I check these values in the shader, they are all imported correctly and contain the correct data. However, when I try to set the variable of shared indices, the vertices are multiplied by arbitrary transformation matrices! They jump to seemingly random positions in space (which differ each time each time), I assume that the indices are set incorrectly, and my shader reads beyond the end of my shared matrix array into the next memory. I'm not quite sure why, because after reading all the information that I could find on this issue, I was surprised to see the same (if not very similar) code in my examples, and it seemed to work for them.
I tried to solve this problem for a long time, and it really starts to get nervous ... I know that the matrices are correct, and when I manually change the index value in the shader to an arbitrary integer, it reads the correct matrix values and works as it should, converting all the vertices to this matrix, but when I try to use the code that I wrote to set the attribute variables, it doesn't seem to work.
The code I use to set the variables is as follows:
// this works properly... GLuint boneMatLoc = glGetUniformLocation([[[obj material] shader] programID], "boneMatrices"); glUniformMatrix4fv( boneMatLoc, matCount, GL_TRUE, currentBoneMatrices ); GLfloat testBoneIndices[8] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; // this however, does not... GLuint boneIndexLoc = glGetAttribLocation([[[obj material] shader] programID], "boneIndices"); glEnableVertexAttribArray( boneIndexLoc ); glVertexAttribPointer( boneIndexLoc, 2, GL_FLOAT, GL_FALSE, 0, testBoneIndices );
And my vertex shader looks like this ...
It really starts to upset me, and any help would be appreciated,
-Andrew Ready