title: Passing uniform 4x4 matrix to vertex shader program
body: <p>I am trying to learn OpenGL and following this: <a href="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/" rel="noreferrer">http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/</a></p>
  
  <p>Up until the point where they started passing matrices to the vertex shader to translate the triangle they where drawing I was following along.</p>
  
  <p>This is the shader program where it starts to go wrong:</p>
  
  <pre><code>#version 330 core
  
  layout(location = 0) in vec3 vertexPosition_modelspace;
  uniform mat4 MVP;
  
  void main(){
      vec4 v = vec4(vertexPosition_modelspace,1); // Transform an homogeneous 4D vector
  
      gl_Position = MVP * v;
  
      //mat4 M = mat4(
      // vec4(1.0, 0.0, 0.0, 0.0),
      // vec4(0.0, 1.0, 0.0, 0.0),
      // vec4(0.0, 0.0, 1.0, 0.0),
      // vec4(0.0, 0.0, 0.0, 1.0)
      //);
      //gl_Position = M * v;
  }
  </code></pre>
  
  <p>If I use the commented out code instead of the line <code>gl_Position = MVP * v;</code>, everything works. A triangle is drawn to the screen. I can also change to <code>M</code> matrix to move the triangle around and scale it.</p>
  
  <p>In order to keep things as simple as possible I am just passing the vertex shader an identity matrix in the MVP field. The code looks like this:</p>
  
  <pre><code>mat4x4 MVP;
  mat4x4_identity(MVP);
  
  int i,j;
  for(i=0; i&lt;4; ++i) {
      for(j=0; j&lt;4; ++j)
          printf("%f, ", MVP[i][j]);
      printf("\n");
  }
  
  GLuint MatrixID = glGetUniformLocation(programID, "MVP");
  
  // Send our transformation to the currently bound shader,
  // in the "MVP" uniform
  // For each model you render, since the MVP will be different (at least the M part)
  glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &amp;MVP[0][0]);
  </code></pre>
  
  <p>I am using linmath.h instead of glm (<a href="https://github.com/datenwolf/linmath.h" rel="noreferrer">https://github.com/datenwolf/linmath.h</a>). The loop prints: </p>
  
  <pre><code>1.000000, 0.000000, 0.000000, 0.000000, 
  0.000000, 1.000000, 0.000000, 0.000000, 
  0.000000, 0.000000, 1.000000, 0.000000, 
  0.000000, 0.000000, 0.000000, 1.000000, 
  </code></pre>
  
  <p>And confirms that MVP is indeed an identity matrix. However when I run the program, I see no triangle on the screen. Only the background (which is dark blue btw).</p>
  
  <p>You can see slightly more of the main C program here: <a href="https://gist.github.com/avwhite/68580376ddf9a7ec9cb7" rel="noreferrer">https://gist.github.com/avwhite/68580376ddf9a7ec9cb7</a></p>
  
  <p>If needed I can also provide the whole source code for the main program, the vertex-, and the fragment shader.</p>
  
  <p>I am thinking this has something to do with how the MVP matrix is passed to the shader program, but I am completely new to OpenGL, so I really have no idea what is going on.</p>