There seems to be a difference between the matrix multiplication in the C++ code and how GLSL do it. I do not transpose my matrices when i load them with GLSL.
The projection and view matrices are taken directly from glm::perspective and glm::lookAt the model is just a identity matrix. So i can't see how it can go wrong.
I stubmled upon this as i was trying to do some shadow projection on a surface. It worked fine when i passed in the shadow matrix as a uniform together with the other 3 matrices. But as soon as i did the multiplication of the shadow unto the model it stopped working. My shadow matrix is correct as far as i can see from testing in matlab, it do rely on perspective divison though done in the shader. But even the following simple matrix operations seem to fail me for some reason.
Works. Parse in different matrices as uniforms together with the vertex as a vec3.
//GLSL gl_Position = projection * view * model * vec4(vertex, 1.0);
Don't work. Parse in a combined matrix as a single uniform together with a vec3.
//C++ mat4 combined = projection * view * model; //GLSL gl_Position = combined * vec4(vertex, 1.0);
Works. Do all the work in C++ and parse the vertex as a vec4 setting it directly in the shader.
//C++ mat4 combined = projection * view * model; vec4 vertex = combined * v; //GLSL gl_Position = vertex;
Thanks for any help.
Im aware that OpenGL is column major and C++ row major. But should GLM not take care of this?
Edited by JeKbe, 09 January 2012 - 07:46 AM.