title: invalid operation on glEnd without cause?
body: <p>I have been working on a GL program for some time now and suddenly it began to give errors.
  After trying to resolve these for a while I wrote a short test program that generates the same behavior:</p>
  
  <pre><code>#include &lt;GL/glut.h&gt;
  #include &lt;iostream&gt;
  
  #define CHECK_GL_ERR() printError(__LINE__)
  
  void printError(int line)
  {
          GLenum err = glGetError();
          if(err != GL_NO_ERROR)
          {
                  std::cerr &lt;&lt; "GL error on line " &lt;&lt; line &lt;&lt; ": " &lt;&lt; gluErrorString(err) &lt;&lt; std::endl;
          }
  }
  
  void displayFunc()
  {
          CHECK_GL_ERR();
          glBegin(GL_POINTS);
          CHECK_GL_ERR();
          glVertex3f(0, 0, 0);
          CHECK_GL_ERR();
          glEnd();
          CHECK_GL_ERR(); //line 23
          exit(0);
  }
  
  int main(int argc, char **argv)
  {
          glutInit(&amp;argc, argv);
          glutInitWindowSize(300, 300);
          glutCreateWindow("Test");
  
          glutDisplayFunc(displayFunc);
  
          glutMainLoop();
  }
  </code></pre>
  
  <p>When I run this program it gives the output:</p>
  
  <pre><code>GL error on line 23: invalid operation
  </code></pre>
  
  <p>So it seems that <code>glEnd();</code> causes the error.
  The docs say:</p>
  
  <blockquote>
    <p>GL_INVALID_OPERATION is generated if glEnd is executed without being
                preceded by a glBegin.</p>
  </blockquote>
  
  <p>Which is not the case in my code. So does anyone see, why this code gives an error message?</p>
  
  <p>PS: Of course I know that glBegin/End has been deprecated/removed for a long time but it is very convenient to hack together some small amounts of code. Also the program worked without errors until GL decided to be grumpy.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I just did a trace with glslDevil which gave:</p>
  
  <pre><code>W! Program Start
  |  glXQueryExtension(0x1ab03f0, (nil), (nil))
  |  glXChooseFBConfig(0x1ab03f0, 0, 0x7fffb8fcf8b0, 0x7fffb8fcf8a4)
  |  glXGetVisualFromFBConfig(0x1ab03f0, 0x111)
  |  glXGetProcAddressARB(0x7f93c37526e5)
  |  glXCreateNewContext(0x1ab03f0, 0x111, 32788, (nil), 1)
  |  glXIsDirect(0x1ab03f0, 0x1ac8de8)
  |  glXMakeContextCurrent(0x1ab03f0, 123731970, 123731970, 0x1ac8de8)
  |  glXMakeContextCurrent(0x1ab03f0, 123731970, 123731970, 0x1ac8de8)
  |  glDrawBuffer(GL_FRONT)
  |  glReadBuffer(GL_FRONT)
  |  glXMakeContextCurrent(0x1ab03f0, 123731970, 123731970, 0x1ac8de8)
  |  glViewport(0, 0, 300, 300)
  |  glXMakeContextCurrent(0x1ab03f0, 123731970, 123731970, 0x1ac8de8)
  |  glXMakeContextCurrent(0x1ab03f0, 123731970, 123731970, 0x1ac8de8)
  |  glGetError()
  |  glBegin(GL_POINTS)
  |  glGetError()
  |  glVertex3f(0,000000, 0,000000, 0,000000)
  |  glGetError()
  |  glEnd()
  W! OpenGL error GL_INVALID_OPERATION detected
  |  glGetError()
  |  glXMakeContextCurrent(0x1ab03f0, 123731970, 123731970, 0x1ac8de8)
  |  glXDestroyContext(0x1ab03f0, 0x1ac8de8)
  E! Child process exited
  W! Program termination forced!
  </code></pre>