title: OpenGL 3.3 lighting gives really strange disortions
body: <p>I've, the last month, been following tutorials on a various pages (<a href="http://learnopengl.com" rel="nofollow noreferrer" title="learopengl.com">learnopengl.com</a>) amongst others.<br>
  I got to the lighting section (I created a loader to load meshes with Assimp first), my fragmentshader code is pretty much the same as the tutorials lighting ( <a href="http://www.learnopengl.com/#!Lighting/Basic-Lighting" rel="nofollow noreferrer">learnopengl.com/basic_lighting</a>).</p>
  
  <p>Frag code:</p>
  
  <pre><code>#version 130
  
  out vec4 outColor;
  
  in vec3 fragPos;
  in vec3 normal;
  in vec2 texcoord;
  
  uniform sampler2D tex;
  uniform vec3 lightPos;
  uniform vec3 lightColor;
  
  void main(){
      float ambientStrength = 0.1f;
      vec3 ambient = ambientStrength * lightColor;
  
      //Diffuse
      vec3 norm = normalize(normal);
      vec3 lightDir = normalize(lightPos - fragPos);
      float diff = max(dot(norm, lightDir), 0.0f);
      vec3 diffuse = diff * lightColor;
      float objectColor = 0.5f;
      //texture(tex, texcoord)
      vec3 result = (ambient + diffuse) * objectColor;
      outColor = vec4(result, 1.0f);
  }
  </code></pre>
  
  <p>When, for example, lighting a plane it gives me these results: </p>
  
  <p><img src="https://i.stack.imgur.com/0BgeP.png" alt="OpenGLplane_light_distortions"></p>
  
  <p>When I'm not lighting the plane it's plain grey.</p>
  
  <p>Here's the .obj file or the plane:</p>
  
  <pre><code>Blender v2.69 (sub 0) OBJ File: 'plane.blend'
  # www.blender.org
  mtllib plane.mtl
  o Plane
  v 10.000000 0.000000 10.000000
  v -10.000000 0.000000 10.000000
  v 10.000000 0.000000 -10.000000
  v -10.000000 0.000000 -10.000000
  vn 0.000000 1.000000 0.000000
  usemtl None
  s off
  f 2//1 1//1 3//1
  f 4//1 2//1 3//1
  </code></pre>
  
  <p>It get's imported correctly, every vertex normal is { 0, 1, 0} and the indices are also correct.</p>
  
  <p>When searching for things like "OpenGL light disortions" or just "OpenGL lighting" I can't find anything like this. So I really have no idea what's wrong.</p>
  
  <p>Oh yeah, I use openGL 3.3, and I have an integrated intel GPU.
  CPU is intel core i3-2367M in case there is a problem with the hardware.</p>
  
  <p>Thank you for your time :D</p>
  
  <p>EDIT: </p>
  
  <p>So I just tried to show the color of my normals on the plane, they should be solid green but they are this abomination:</p>
  
  <p><img src="https://i.stack.imgur.com/2P9GW.png" alt="OpenGL disortion Normals"></p>
  
  <p>I'll also dump my vertexshadercode in here: </p>
  
  <pre><code>#version 130
  in vec3 position;
  in vec3 normal;
  in vec2 texCoord;
  
  
  out vec3 fragPos;
  out vec3 Normal;
  out vec2 texcoord;
  
  uniform mat4 transform;
  uniform mat4 view;
  uniform mat4 projection;
  
  void main(){
      texcoord = texCoord;
      Normal = normal;
      fragPos = vec3(transform * vec4(position, 1.0f));
      gl_Position = projection * view * transform * vec4(position, 1.0);
  }
  </code></pre>
  
  <p>Here's how I set up my mesh:</p>
  
  <pre><code>void mesh::bindVertices(){
      glBindVertexArray(vertexArrayObject);
  
      glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
      glBufferData(GL_ARRAY_BUFFER, this-&gt;vertices.size() * sizeof(Vertex), &amp;vertices[0], GL_STATIC_DRAW);
  
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, this-&gt;indices.size() * sizeof(GLuint), &amp;indices[0], GL_STATIC_DRAW);
  
  
  
      glEnableVertexAttribArray(0);
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)0); // Position
  
      glEnableVertexAttribArray(1);
      glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, normal)); //Normal
  
      glEnableVertexAttribArray(2);
      glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, texCoord)); //Texcoord
  
  
      glBindVertexArray(0);
  
  }
  </code></pre>
  
  <p>Vertex.h</p>
  
  <pre><code>#ifndef VERTEX_H
  #define VERTEX_H
  
  #include &lt;vector&gt;
  #include &lt;glm/glm.hpp&gt;
  
  class Vertex
  {
      public:
          Vertex(){
              position = glm::vec3(0.0f, 0.0f, 0.0f);
              normal = glm::vec3(0.0f, 0.0f, 0.0f);
              texCoord = glm::vec2(0.0f, 0.0f);
          };
  
          Vertex(glm::vec3 pos, glm::vec3 nor, glm::vec2 tex){
              setUpVertex(pos, nor, tex);
          };
          ~Vertex(){}
  
          void setUpVertex(glm::vec3 pos, glm::vec3 nor, glm::vec2 tex){
              this-&gt;position = pos;
              this-&gt;normal = nor;
              this-&gt;texCoord = tex;
          };
  
          void print(){
               std::cout &lt;&lt; "Position: { " &lt;&lt; position.x &lt;&lt; ", " &lt;&lt; position.y &lt;&lt; ", " &lt;&lt; position.z &lt;&lt; " }\n";
              std::cout &lt;&lt; "Normals: { " &lt;&lt; normal.x &lt;&lt; ", " &lt;&lt; normal.y &lt;&lt; ", " &lt;&lt; normal.z &lt;&lt; " }\n";
              std::cout &lt;&lt; "Texture Coordinates: { " &lt;&lt; texCoord.x &lt;&lt; ", " &lt;&lt; texCoord.y &lt;&lt; " }" &lt;&lt; std::endl;
          }
          glm::vec3 position;
          glm::vec3 normal;
          glm::vec2 texCoord;
  
      protected:
      private:
  
  };
  
  #endif // VERTEX_H
  </code></pre>
  
  <p>The print function is there for debugging, and it outputs the correct values, so I really have no idea what is going on. 
  <br>One thing that is not a problem is loading in the model is what I've managed to gather and the normals are behaving very strangley.</p>