Problems with using mat4 vertex attribute

Hello!

I've got this problem where i'm sending all my vertices in one buffer object and
all it's model matrices in another. The problem is that is seems that vertex shader is only getting the first model matrix (or none)
because all the models are drawn in the same place.

I don't see the code that's actually doing the draw call. Are you using an instanced draw method (glDrawArraysInstanced, glDrawElementsInstanced)? Otherwise the instance will always be 0 unless you use one of the ...BaseInstance draw variants.

I'm not in fact using any object instancing, just plain old glDrawArray. Is it even possible to use mat4 attribute without using instancing?
I've tested the code by using only position vectors that I've pulled from the model matrices and then send them as vec3 attributes, and it works just fine.

malexander probably thought you were using instancing because you have a glVertexAttribDivisor call in your code. I don't think it should do any harm, but you may want to keep that at 0 if you're not using instancing.

I haven't been able to spot a problem with the setup of the matrix vertex attribute so far.

You do have a problem with your texture setup, but that's probably unrelated. Assuming that "tex" is a sampler in your fragment shader, the value of the uniform variable must be the index of the texture unit you bind it to. In your case, you need to set the value of that uniform to 0. Also, how do you know that your texture id is 1? Are you using that as a fixed value? That might still work depending on the OpenGL profile you're using, but using your own texture ids is deprecated. You need to use glGenTextures() to generate the ids (or "names", as the spec likes to call them) in the core profile.

malexander probably thought you were using instancing because you have a glVertexAttribDivisor call in your code. I don't think it should do any harm, but you may want to keep that at 0 if you're not using instancing...

That did the trick
Phew, been hammering this problem for days, thanks a bunch!

Awesome, thanks for reporting back. I was initially surprised that it helped, because I expected that the value only mattered when instancing was used. But after going back to the spec, this is the value that actually enables instancing for the attribute:

If divisor is zero, the attribute at slot index advances once per vertex. If divisor is non-zero, the attribute advances once per divisor instances of the set(s) of vertices being rendered.