opengl - sending array to shader with glUniformMatrix -
i have model matdexs (read matrix index) either 0, 1, , 2 evenly distributed. bonebends[matdex[whichvertex]] tells matrix should used on vertex.
initializing, c++:
std::vector< glint > matdex; //initialized 0, 1, or 2 each vertex loaded, not shown brevity std::vector<glm::mat4> bonebends; int frames=0; bonebends.push_back(glm::mat4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)); //identity matrices bonebends.push_back(glm::mat4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)); bonebends.push_back(glm::mat4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)); // thats 3 bones ver_ind = glgetattriblocation(shaderid, "ver_ind"); boneid = glgetuniformlocation(shaderid, "bone_matrix[0]"); glgenbuffers(1, &ind_buff); glbindbuffer(gl_array_buffer, ind_buff); glbufferdata(gl_array_buffer, matdex.size() * sizeof(glint), &matdex[0], gl_static_draw); periodically in main loop, c++:
glenablevertexattribarray(3); //ind glbindbuffer(gl_array_buffer, ind_buff); glvertexattribpointer( ver_ind, 1, gl_int, gl_false, 0, (void*)0 ); //also here gluniformmatrix4fv(boneid, 3 , gl_false, &bonebends[0][0][0]); frames+=1; float cs=cos(3.14*2.0*(frames/100.0)); float sn=sin(3.14*2.0*(frames/100.0)); // here bonebends[0]=glm::mat4( cs , 0,-sn,0 , 0 , 1, 0,0 , sn, 0, cs,0 , 0 , 0, 0,1 ); in shader, glsl:
layout(location = 3) in int ver_ind; uniform mat4 bone_matrix[3]; in main function of shader, glsl:
gl_position = bone_matrix[ver_ind] * vec4(ver_pos,1); //ver_pos vertex's coordinates i hoped make vertices coinciding matdex of 0 rotate, , rest remain stationary. instead displays model (which otherwise rendered correctly) spinning, if matdexs values equal 0. little couting tells me not. don't know how debug ver_ind in shader.
tried
- using
uintinstead ofintincarnations ofmatdex, didn't make difference. - changing
bone_matrix[ver_ind]bone_matrix[0]in shader, made crash(???) - changing second , fourth argument of
gluniformmatrix4fv(boneid, 3 , gl_false, &bonebends[0][0][0]);in various ways, didn't help. - changed
matdexs values such none of them 0, , still rotates if shader usingbone_matrix[0]. - changing line below
// herebonebends[1]=glm::mat4(results in model not spinning @ all.
from concluded ever using first of bone_matrix[3], because shader isn't receiving correctly. can post whole thing bit lengthy.
know doing wrong , how information shader.
there lot of problems.
first, matdex empty. you're not getting actual information.
second,
layout(location = 3) in int ver_ind; glvertexattribpointer( ver_ind, 1, gl_int, gl_false, 0, (void*)0 ); these 2 things cannot work together. glvertexattribpointer can feed floating-point inputs. if use integer formats gl_int, they converted floats. if want feed integer inputs, must use glvertexattribipointer (note i).
or make ver_ind float. , pass glubytes instead of glints. really, there's no point in taking of memory.
third:
glenablevertexattribarray(3); //ind glvertexattribpointer( ver_ind, 1, gl_int, gl_false, 0, (void*)0 ); the first parameter of both of these functions should the same, if you're trying enable ver_ind.
fourth:
//also here gluniformmatrix4fv(boneid, 3 , gl_false, &bonebends[0][0][0]); i don't see use gluseprogram set program wanted change uniform data on.
fifth:
// here bonebends[0]=glm::mat4( changing value after have uploaded not magically cause uploaded value change.
there may (and are) more problems, code posted incomplete , don't intend personal debugger. @ least, start code know works, make smallest change leading towards want. working, make change. , on. did bunch of stuff @ once, , didn't work out.
Comments
Post a Comment