title: OpenGL and GLM matrix doesn't scale properly, always scales down
body: <p>When I use glm::scale to update the model matrix in my vertex shader, no matter what I do, it will always scale it down. Anyone know what I'm doing wrong? The image will sometimes flip up and down too.</p>
  <p>The key == 'w' and key == 's' do the exact same thing despite the code being different, the goal is to make the model grow bigger by pressing W and smaller by pressing S. But right now it just gets smaller with both presses.</p>
  <p>The relevant code used to scale according to key press is:</p>
  <pre><code>if (key == 'w') {
          model = glm::scale(model, glm::vec3(0.5, 0.5, 0.5));
          int loc = glGetUniformLocation(prog, &quot;model&quot;);
          glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model));
      }
      if (key == 's') {
          model = glm::scale(model, glm::vec3(-0.5, -0.5, -0.5));
          int loc = glGetUniformLocation(prog, &quot;model&quot;);
          glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model));
      }
  </code></pre>
  <p>The whole code is:</p>
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;GL\glew.h&gt;
  #include &lt;GL\freeglut.h&gt;
  #include &lt;iostream&gt;
  #include &lt;SOIL.h&gt;
  #include &lt;glm/glm.hpp&gt;
  #include &lt;glm/gtc/matrix_transform.hpp&gt;
  #include &lt;glm/gtc/type_ptr.hpp&gt;
  #include &quot;OBJ.h&quot;
  
  const char* vs = &quot;#version 330 core\n&quot;
  &quot;layout (location = 0) in vec3 pos;\n&quot;
  &quot;layout (location = 1) in vec2 texpos;\n&quot;
  &quot;out vec2 texCoords;\n&quot;
  &quot;uniform mat4 model;\n&quot;
  &quot;uniform mat4 view;\n&quot;
  &quot;uniform mat4 projection;\n&quot;
  &quot;void main()\n&quot;
  &quot;{\n&quot;
  &quot;gl_Position = projection * view * model * vec4(pos, 1);\n&quot;
  &quot;texCoords = texpos;\n&quot;
  &quot;}\0&quot;;
  
  const char* fs = &quot;#version 330 core\n&quot;
  &quot;in vec2 texCoords;\n&quot;
  &quot;out vec4 fragColor;\n&quot;
  &quot;uniform sampler2D tex;\n&quot;
  &quot;void main()\n&quot;
  &quot;{\n&quot;
  &quot;fragColor = texture(tex, texCoords);&quot;
  &quot;}\0&quot;;
  
  float verts[] = {
      0, 1, 0, 0.5, 1,
      -1, -1, 0, 0, 0,
      1, -1, 0, 1, 0
  };
  
  unsigned short indices[] = {
      0, 1, 2
  };
  
  unsigned int vao, vbo, ebo, prog, vert, frag, texid;
  
  glm::mat4 model, view, projection;
  
  
  void changeViewPort(int w, int h)
  {
      glViewport(0, 0, w, h);
  }
  
  void render()
  {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glBindVertexArray(vao);
      glBindTexture(GL_TEXTURE_2D, texid);
      glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, 0);
      glutSwapBuffers();
  }
  
  void initGL() {
      //Context stuff
      glViewport(0, 0, 800, 600);
      glClearColor(0.5, 0.5, 0.5, 1);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
      //Shader stuff
      int success;
      prog = glCreateProgram();
      vert = glCreateShader(GL_VERTEX_SHADER);
      glShaderSource(vert, 1, &amp;vs, NULL);
      glCompileShader(vert);
      glGetShaderiv(vert, GL_COMPILE_STATUS, &amp;success);
      std::cout &lt;&lt; &quot;Vertex shader &quot; &lt;&lt; (success ? &quot;compiled&quot; : &quot;not compiled&quot;) &lt;&lt; std::endl;
  
      frag = glCreateShader(GL_FRAGMENT_SHADER);
      glShaderSource(frag, 1, &amp;fs, NULL);
      glCompileShader(frag);
      glGetShaderiv(frag, GL_COMPILE_STATUS, &amp;success);
      std::cout &lt;&lt; &quot;Fragment shader &quot; &lt;&lt; (success ? &quot;compiled&quot; : &quot;not compiled&quot;) &lt;&lt; std::endl;
  
      glAttachShader(prog, vert);
      glAttachShader(prog, frag);
  
      glLinkProgram(prog);
      glUseProgram(prog);
  
      glGetShaderiv(prog, GL_LINK_STATUS, &amp;success);
      std::cout &lt;&lt; &quot;Program &quot; &lt;&lt; (success ? &quot;linked&quot; : &quot;not linked&quot;) &lt;&lt; std::endl;
  
      glDeleteShader(vert);
      glDeleteShader(frag);
      //Vertex stuff
      glGenVertexArrays(1, &amp;vao);
      glBindVertexArray(vao);
  
      glGenBuffers(1, &amp;vbo);
      glGenBuffers(1, &amp;ebo);
  
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      glBufferData(GL_ARRAY_BUFFER, sizeof(verts), &amp;verts, GL_STATIC_DRAW);
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GL_FLOAT), 0);
      glEnableVertexAttribArray(0);
      glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GL_FLOAT), (void*)(3 * sizeof(GL_FLOAT)));
      glEnableVertexAttribArray(1);
  
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &amp;indices, GL_STATIC_DRAW);
  
      glBindBuffer(GL_ARRAY_BUFFER, 0);
      glBindVertexArray(0);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
      //Texture stuff
      int width, height;
      unsigned char* texData = SOIL_load_image(&quot;brick.png&quot;, &amp;width, &amp;height, NULL, SOIL_LOAD_RGBA);
  
      glGenTextures(1, &amp;texid);
      glBindTexture(GL_TEXTURE_2D, texid);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  
      if (texData) {
          glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
          glGenerateMipmap(GL_TEXTURE_2D);
      } else {
          std::cout &lt;&lt; &quot;Texture not loaded.&quot; &lt;&lt; std::endl;
      }
      glBindTexture(GL_TEXTURE_2D, 0);
      SOIL_free_image_data(texData);
  
      //Matrix stuff
      //Model matrix
      model = glm::mat4(1.0f);
      model = glm::scale(model, glm::vec3(0.5, 0.5, 0.5));
      int modelMatrix = glGetUniformLocation(prog, &quot;model&quot;);
      glUniformMatrix4fv(modelMatrix, 1, GL_FALSE, glm::value_ptr(model));
      //View matrix
      view = glm::mat4(1.0f);
      view = glm::translate(view, glm::vec3(0, 0, -3));
      int viewMatrix = glGetUniformLocation(prog, &quot;view&quot;);
      glUniformMatrix4fv(viewMatrix, 1, GL_FALSE, glm::value_ptr(view));
      //Projection matrix, something is messing up here
      projection = glm::mat4(1.0f);
      projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f);
      int projectionMatrix = glGetUniformLocation(prog, &quot;projection&quot;);
      glUniformMatrix4fv(projectionMatrix, 1, GL_FALSE, glm::value_ptr(projection));
  
  }
  
  void input(unsigned char key, int x, int y) {
      if (key == 'a') {
          model = glm::translate(model, glm::vec3(-0.5, 0, 0));
          int loc = glGetUniformLocation(prog, &quot;model&quot;);
          glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model));
      }
      if (key == 'd') {
          model = glm::translate(model, glm::vec3(0.5, 0, 0));
          int loc = glGetUniformLocation(prog, &quot;model&quot;);
          glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model));
      }
      if (key == 'w') {
          model = glm::scale(model, glm::vec3(0.5, 0.5, 0.5));
          int loc = glGetUniformLocation(prog, &quot;model&quot;);
          glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model));
      }
      if (key == 's') {
          model = glm::scale(model, glm::vec3(-0.5, -0.5, -0.5));
          int loc = glGetUniformLocation(prog, &quot;model&quot;);
          glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model));
      }
      if (key == 'q') {
  
          model = glm::rotate(model, glm::radians(45.0f), glm::vec3(0, 0, 1));
          int loc = glGetUniformLocation(prog, &quot;model&quot;);
          glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model));
      }
      if (key == 'e') {
  
          model = glm::rotate(model, glm::radians(-45.0f), glm::vec3(0, 0, 1));
          int loc = glGetUniformLocation(prog, &quot;model&quot;);
          glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(model));
      }
      glutPostRedisplay();
  }
  
  int main(int argc, char* argv[]) {
  
      // Initialize GLUT
      glutInit(&amp;argc, argv);
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
      glutInitWindowSize(800, 600);
      glutCreateWindow(&quot;OBJ Viewer&quot;);
      glutReshapeFunc(changeViewPort);
      glutDisplayFunc(render);
      glutKeyboardFunc(input);
      GLenum err = glewInit();
      if (GLEW_OK != err) {
          fprintf(stderr, &quot;GLEW error&quot;);
          return 1;
      }
      initGL();
      glutMainLoop();
      return 0;
  }
  </code></pre>