title: GLSL syntax problems: unexpected NEW_IDENTIFIER
body: <p>I have just started to learn OpenGL, and am following <a href="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/" rel="noreferrer">this</a> tutorial. I am having difficulty compiling the GLSL files that the tutorial uses.</p>
  
  <p>Originally when I tried compiling them the compiler said that mesa did not support GLSL version 330 so I changed <code>#version 330 core</code> to <code>#version 130</code>. Now when I run it it gives me the following error:</p>
  
  <pre><code>3.0 Mesa 10.0.20Compiling shader : SimpleVertexShader.vertexshader
  0:3(1): error: syntax error, unexpected NEW_IDENTIFIER
  
  Compiling shader : SimpleFragmentShader.fragmentshader
  
  Linking program
  error: linking with uncompiled shader
  </code></pre>
  
  <p>I have searched on google and cannot find anyone with this problem. Anyway, here are all of the files in question:</p>
  
  <p>SimpleVertexShader.vertexshader:</p>
  
  <pre><code>#version 130
  layout(location = 0) in vec3 vertexPosition_modelspace;
  
  void main(){
      gl_Position.xyz = vertexPosition_modelspace;
      gl_Position.w = 1.0;
  }
  </code></pre>
  
  <p>SimpleFragmentShader.fragmentshader:</p>
  
  <pre><code>#version 130
  out vec3 color;
  
  void main() {
      color = vec3(1,0,0);
  }
  </code></pre>
  
  <p>loadShader.cpp:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #include &lt;GL/glew.h&gt;
  
  GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){
  
      // Create the shaders
      GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
      GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
  
      // Read the Vertex Shader code from the file
      std::string VertexShaderCode;
      std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
      if(VertexShaderStream.is_open())
      {
          std::string Line = "";
          while(getline(VertexShaderStream, Line))
              VertexShaderCode += "\n" + Line;
          VertexShaderStream.close();
      }
  
      // Read the Fragment Shader code from the file
      std::string FragmentShaderCode;
      std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
      if(FragmentShaderStream.is_open()){
          std::string Line = "";
          while(getline(FragmentShaderStream, Line))
              FragmentShaderCode += "\n" + Line;
          FragmentShaderStream.close();
      }
  
      GLint Result = GL_FALSE;
      int InfoLogLength;
  
      // Compile Vertex Shader
      printf("Compiling shader : %s\n", vertex_file_path);
      char const * VertexSourcePointer = VertexShaderCode.c_str();
      glShaderSource(VertexShaderID, 1, &amp;VertexSourcePointer , NULL);
      glCompileShader(VertexShaderID);
  
      // Check Vertex Shader
      glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &amp;Result);
      glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &amp;InfoLogLength);
      std::vector&lt;char&gt; VertexShaderErrorMessage(InfoLogLength);
      glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &amp;VertexShaderErrorMessage[0]);
      fprintf(stdout, "%s\n", &amp;VertexShaderErrorMessage[0]);
  
      // Compile Fragment Shader
      printf("Compiling shader : %s\n", fragment_file_path);
      char const * FragmentSourcePointer = FragmentShaderCode.c_str();
      glShaderSource(FragmentShaderID, 1, &amp;FragmentSourcePointer , NULL);
      glCompileShader(FragmentShaderID);
  
      // Check Fragment Shader
      glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &amp;Result);
      glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &amp;InfoLogLength);
      std::vector&lt;char&gt; FragmentShaderErrorMessage(InfoLogLength);
      glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &amp;FragmentShaderErrorMessage[0]);
      fprintf(stdout, "%s\n", &amp;FragmentShaderErrorMessage[0]);
  
      // Link the program
      fprintf(stdout, "Linking program\n");
      GLuint ProgramID = glCreateProgram();
      glAttachShader(ProgramID, VertexShaderID);
      glAttachShader(ProgramID, FragmentShaderID);
      glLinkProgram(ProgramID);
  
      // Check the program
      glGetProgramiv(ProgramID, GL_LINK_STATUS, &amp;Result);
      glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &amp;InfoLogLength);
      std::vector&lt;char&gt; ProgramErrorMessage( max(InfoLogLength, int(1)) );
      glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &amp;ProgramErrorMessage[0]);
      fprintf(stdout, "%s\n", &amp;ProgramErrorMessage[0]);
  
      glDeleteShader(VertexShaderID);
      glDeleteShader(FragmentShaderID);
  
      return ProgramID;
  }
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;GL/glew.h&gt;
  //#define GLFW_DLL // maybe some glu problems - look up
  #include &lt;GLFW/glfw3.h&gt;
  #include &lt;glm/glm.hpp&gt;
  
  GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path);
  
  int main()
  {
      GLFWwindow * window;
  
      if (!glfwInit()) {
          std::cout &lt;&lt; "Failed to initiate GLFW\n";
          return -1;
      }
  
      glfwWindowHint(GLFW_SAMPLES, 4); //4x antialiasing
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //version 3
  
      //open a window and create context
      window=glfwCreateWindow(1024,768,"Lerning", glfwGetPrimaryMonitor(), NULL);
      if (!window) {
          std::cout &lt;&lt; "Failed to open window\n";
          glfwTerminate();
          return -1;
      }
  
      glfwMakeContextCurrent(window);
      std::cout &lt;&lt; glGetString(GL_VERSION);
  
      // initialize GLEW
      glewExperimental=GL_TRUE; //needed
      GLenum err = glewInit();
      std::cout &lt;&lt; err;
      if (err != GLEW_OK) {
          std::cout &lt;&lt; "Failed to initialize\n" &lt;&lt; glewGetErrorString(err);
          return -1;
      }
  
      GLuint VertexArrayID;
      glGenVertexArrays(1, &amp;VertexArrayID);
      glBindVertexArray(VertexArrayID);
  
      static const GLfloat g_vertex_buffer_data[] = {
          -1.0f, -1.0f, 0.0f,
          1.0f, 1.0f, 0.0f,
          0.0f, 1.0f, 0.0f,
      };
  
      GLuint vertexbuffer;
      glGenBuffers(1, &amp;vertexbuffer);
      glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
      glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data),
              g_vertex_buffer_data, GL_STATIC_DRAW);
  
      GLuint programID = LoadShaders("SimpleVertexShader.vertexshader",
              "SimpleFragmentShader.fragmentshader");
  
      while (!glfwWindowShouldClose(window)) {
  
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
          glUseProgram(programID);
  
          glEnableVertexAttribArray(0);
          glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
          glVertexAttribPointer(
                  0,
                  3,
                  GL_FLOAT,
                  GL_FALSE,
                  0,
                  (void*)0
          );
  
          glDrawArrays(GL_TRIANGLES, 0, 3);
          glDisableVertexAttribArray(0);
  
          glfwSwapBuffers(window);
          glfwPollEvents();
      }
  
      glfwTerminate();
      return 0;
  }
  </code></pre>