title: glewinit() apparently successful, sets error flag anyway
body: <p>I have recently migrated from Windows to Linux (Debian, 64-bit) and am trying to get a GPGPU development environment up and running, so I am testing a program which worked under Windows.</p>
  
  <p>Compiling and linking goes fine, but when I run the program I get some odd errors. I am using glew and freeglut. </p>
  
  <p><strong>First snippet: OpenGL only</strong></p>
  
  <pre><code>i = 1;
  info = PROGRAM_NAME;
  glutInitContextVersion(4,2);
  glutInit(&amp;i, &amp;info);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
  glutInitWindowSize(W_SIZEX, W_SIZEY);
  glutInitWindowPosition(W_POSX, W_POSY);
  glutCreateWindow(info);
  glClearColor(1.0,1.0,1.0,0);
  /**/
  printf("Before glewInit: %i\n", glGetError());
  /**/    
  printf("glewInit returns: %i\n", glewInit());
  /**/
  printf("After glewInit: %i\n", glGetError());
  /**/
  </code></pre>
  
  <p>From which I get the following output:</p>
  
  <pre><code>Before glewInit: 0
  glewInit returns: 0
  After glewInit: 1280
  </code></pre>
  
  <p>This is an invalid enum error. I don't know what's causing it, but I suspect it might be related to the next error I get, later in the program's execution.</p>
  
  <p><strong>Second snippet: OpenCL-OpenGL interop</strong></p>
  
  <pre><code>/* BUFFERS */
  (*BFR).C[0] = clCreateBuffer(*CTX, CL_MEM_READ_WRITE, SD, 0, 0);
  (*BFR).C[1] = clCreateBuffer(*CTX, CL_MEM_READ_WRITE, SD, 0, &amp;i);
  dcl(i);
  
  glGenBuffers(2, (*BFR).G);
  
  glBindBuffer(GL_ARRAY_BUFFER, (*BFR).G[0]);
  glBufferData(GL_ARRAY_BUFFER, SI, 0, GL_DYNAMIC_DRAW);
  (*BFR).D[0] = clCreateFromGLBuffer(*CTX, CL_MEM_WRITE_ONLY, (*BFR).G[0], &amp;i);
  dcl(i);
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  </code></pre>
  
  <p>Here, the dcl(int) method just decodes the CL error code. When I run this, I get a CL_INVALID_GL_OBJECT error from clCreateFromGLBuffer(). However, OpenGL has no issues generating, binding or unbinding the buffers in question. The OpenCL context is apparently valid, generating no errors on creation or query. Everything works in VS2010 on Windows 7 64-bit.</p>
  
  <p><strong>Compilation Details</strong></p>
  
  <p>Here are the relevant includes:</p>
  
  <pre><code>/* OPENGL */
  #include "GL/glew.h"
  #include "GL/freeglut.h"
  
  /* OPENCL */
  #include "CL/cl.h"
  #include "CL/cl_gl.h"
  </code></pre>
  
  <p>I am using GCC and linking like so:</p>
  
  <pre><code>gcc -w -I./include CLGL.c -o ~/Templates/GOL-CLGL/run/a.out -lGLEW -lGLU -lglut -lGL -lOpenCL;
  </code></pre>
  
  <p>Compilation and linking results in no errors (plenty of warnings about pointer abuse but I doubt that's the culprit).</p>
  
  <p>I'm currently out of ideas on how to debug this. Can anyone suggest further steps?</p>