title: OpenGL (in Ubuntu): glGetError() returns GL_INVALID_OPERATION
body: <p>For OpenGL learning, I am referring to <a href="http://openglbook.com/the-book/" rel="nofollow">openglbook</a>. Currently in <a href="http://openglbook.com/the-book/chapter-2-vertices-and-shapes/" rel="nofollow">chapter 2</a>, I am trying to run its code which is <a href="http://ideone.com/7QN8X" rel="nofollow">pasted here</a> for reference.</p>
  
  <p>The problem I am facing is with below function:</p>
  
  <pre><code>void CreateShaders(void)
  {
      GLenum ErrorCheckValue = glGetError();
  
      VertexShaderId = glCreateShader(GL_VERTEX_SHADER);
      glShaderSource(VertexShaderId, 1, &amp;VertexShader, NULL);
      glCompileShader(VertexShaderId);
  
      FragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
      glShaderSource(FragmentShaderId, 1, &amp;FragmentShader, NULL);
      glCompileShader(FragmentShaderId);
  
      ProgramId = glCreateProgram();
          glAttachShader(ProgramId, VertexShaderId);
          glAttachShader(ProgramId, FragmentShaderId);
      glLinkProgram(ProgramId);
      glUseProgram(ProgramId);
  
      ErrorCheckValue = glGetError(); // =====&gt; returns GL_INVALID_OPERATION
      if (ErrorCheckValue != GL_NO_ERROR)
      {
          fprintf(
              stderr,
              "ERROR: Could not create the shaders: %s \n",
              gluErrorString(ErrorCheckValue)
          );
  
          exit(-1);
      }
  }
  </code></pre>
  
  <p>As shown in above function(<code>glew.h</code>), why does it return <code>"GL_INVALID_OPERATION"</code> ?<br>
  If I comment those line, then it works but just prints a blank window.  </p>
  
  <p>Here is my <a href="http://ideone.com/6DyQN" rel="nofollow">glxinfo</a>. Since my version is 2.2 and this code is meant for 3.3+, I have removed below code to avoid failure:</p>
  
  <pre><code>  glutInitContextVersion(4, 0); 
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);
  </code></pre>
  
  <p><strong>Update</strong>: After following suggestions from @Tim's answer, I was able to run the program successfully; it seems that these lines were creation problem:</p>
  
  <blockquote>
    <p>"#version 400\n" (replaced with "#version 130")</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>layout(location=0) (removed).
    layout(location=1) (removed).</p>
  </blockquote>
  
  <p>However due to this the expected triangle is not printed exactly same.  Probably the tutorial teaches with latest opengl version in mind, which I don't have and that creates the problem.</p>
  
  <p><em>Is there any way to modify the code from latest OpenGL (4.0+) compatible code to lesser versions (e.g. &lt; 3.0) without altering the output ?</em> I won't be able to upgrade the graphics hardware.</p>