title: OpenGL Shader fails to compile
body: <p>I'm currently trying to get into OpenGL. Unfortunately my shaders always fail to compile. The textfiles storing the shaders are successfully read into the string and passed to the glShaderSource - function. Since everything up to this point works i think my error is somewhere in the shader files themselves (vertex shader, fragment shader). I tried to output the error code, but i only get strange symbols.</p>
  
  <pre><code>    void GLSLProgram::compileShaders(const std::string&amp; vertexShaderFilePath, const std::string&amp; fragmentShaderFilepath)
  {
      _programID = glCreateProgram();
      _vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
      _fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
  
      if (_vertexShaderID == 0){
          fatalError("Vertex shader failed to be created !");
      }
      _fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
      if (_fragmentShaderID == 0){
          fatalError("Fragment shader failed to be created !");
      }
  
      compileShader(vertexShaderFilePath, _vertexShaderID);
      compileShader(fragmentShaderFilepath, _fragmentShaderID);
  
      return;
  }
  
  void GLSLProgram::compileShader(const std::string&amp; filePath, GLuint&amp; id)
  {
      std::ifstream vertexFile(filePath); 
  
      if (vertexFile.fail()){
          fatalError("Failed to open " + filePath);
          perror(filePath.c_str());
      }
  
      std::string fileContents = "";
      std::string line;
  
      while (std::getline(vertexFile, line)){
          fileContents.append(line + '\n');
      }
  
      vertexFile.close();
      const GLchar* contentsPtr = fileContents.c_str();
      glShaderSource(id, 1, &amp;contentsPtr, nullptr); 
  
      glCompileShader(id);
  
      GLint success = 0;
      glGetShaderiv(id, GL_COMPILE_STATUS, &amp;success); //returns success of most recent compilation
      if (success == GL_FALSE)
      {
          GLint maxLength = 0;
          glGetShaderiv(id, GL_INFO_LOG_LENGTH, &amp;maxLength);
  
          // The maxLength includes the NULL character
          std::vector&lt;char&gt; errorLog(maxLength);
          glGetShaderInfoLog(id, maxLength, &amp;maxLength, &amp;errorLog[0]);
  
          // Provide the infolog in whatever manor you deem best.
          // Exit with failure.
          glDeleteShader(id); // Don't leak the shader.
  
          std::printf("%s\n", errorLog);
          fatalError("shader " + filePath + "failed to compile");
  
      }
  }
  </code></pre>
  
  <p>Fragment shader:</p>
  
  <pre><code>#version 130
  
  out vec3 color;
  
  void main(){
      color = vec3(1.0, 0.0, 0.0);
  }
  </code></pre>
  
  <p>Vertex Shader:</p>
  
  <pre><code>#version 130
  
  in vec2 vertexPosition;
  
  void main() {
      gl_Position.xy = vertexPosition;
      gl_Positionsition.z = 0.0;
      gl_Position.w = 1.0;
  }
  </code></pre>