title: How to properly initialize a model matrix in C?
body: <p>I tried to convert the code of the question I asked over <a href="https://stackoverflow.com/questions/49651388/why-is-the-sprite-not-rendering-in-opengl">here</a>.</p>
  
  <p>But when I try to run it, I run into an exception and it points to the mat4(which is an 2-d array of 4x4 floats) header of <a href="https://github.com/recp/cglm" rel="nofollow noreferrer">this</a>(CGLM, which is use for OpenGL math in C as GLM is C++ only library) library.</p>
  
  <p>The C++ code works fine and runs perfectly but why does it crash in C.</p>
  
  <p>Here is the C snippet of the code where 'CGLM' is used(this is the code that crashes):-</p>
  
  <pre><code>glUseProgram(shaderProgram);
  mat4 model =
  {
      { 1.0f, 0.0f, 0.0f, 0.0f },
      { 0.0f, 1.0f, 0.0f, 0.0f },
      { 0.0f, 0.0f, 1.0f, 0.0f },
      { 0.0f, 0.0f, 0.0f, 1.0f },
  };
  mat4 projection;
  glm_ortho(0.0f, (GLfloat)(WIDTH), (GLfloat)(HEIGHT), 0.0f, -1.0f, 1.0f, projection);
  
  vect2 scale = { 2.0f, 2.0f };
  vect2 position = { 50.0f, 0.0f };
  vec4 color = { 1.0f, 1.0f, 1.0f, 0.5f };
  GLfloat rotation = 0.0f;
  
  glm_translate(model, (vec3){ position[0], position[1], 0.0f });
  
  glm_translate(model, (vec3){ 0.5f * scale[0], 0.5f * scale[1], 0.0f });
  glm_rotate(model, rotation, (vec3){ 0.0f, 0.0f, 1.0f }); // Why is this function crashing?
  glm_translate(model, (vec3){ -0.5f * scale[0], -0.5f * scale[1], 0.0f });
  
  glm_scale(model, (vec3){ scale[0] * width, scale[1] * height, 1.0f });
  
  glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "projection"), 1, GL_FALSE, (GLfloat *)projection);
  glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "model"), 1, GL_FALSE, (GLfloat *)model);
  glUniform4f(glGetUniformLocation(shaderProgram, "spriteColor"), color[0], color[1], color[2], color[3]);
  </code></pre>
  
  <p>Here is the C++ snippet of the code where GLM is used:-</p>
  
  <pre><code>glUseProgram(shaderProgram);
  glm::mat4 model(1.0f);
  glm::mat4 projection = glm::ortho(0.0f, static_cast&lt;GLfloat&gt;(WIDTH), static_cast&lt;GLfloat&gt;(HEIGHT), 0.0f, -1.0f, 1.0f);
  
  glm::vec2 scale = glm::vec2(2.0f, 2.0f);
  glm::vec2 position = glm::vec2(50.0f, 0.0f);
  glm::vec4 color = glm::vec4(1.0f, 1.0f, 1.0f, 0.5f);
  GLfloat rotation = 0.0f;
  
  model = glm::translate(model, glm::vec3(position, 0.0f));
  
  model = glm::translate(model, glm::vec3(0.5f * scale.x, 0.5f * scale.y, 0.0f));
  model = glm::rotate(model, rotation, glm::vec3(0.0f, 0.0f, 1.0f));
  model = glm::translate(model, glm::vec3(-0.5f * scale.x, -0.5f * scale.y, 0.0f));
  
  model = glm::scale(model, glm::vec3(scale * glm::vec2(width, height), 1.0f));
  
  glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
  glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "model"), 1, GL_FALSE, glm::value_ptr(model));
  glUniform4f(glGetUniformLocation(shaderProgram, "spriteColor"), color.x, color.y, color.z, color.w);
  </code></pre>