title: OpenGL 3.3 + OSX + GLFW Does not work
body: <p>I'm following the <a href="http://opengl-tutorials.org" rel="nofollow noreferrer">http://opengl-tutorials.org</a> tutorial series, and came up with a very basic code for drawing a white triangle on screen, but I can't seem to get it to work.</p>
  
  <p>I've compiled glfw without any additional options using appleshell's answer here: <a href="https://stackoverflow.com/questions/23450334/opengl-3-3-4-1-on-mac-osx-10-9-using-glfw-library">OpenGL 3.3/4.1 on Mac OSX 10.9 using GLFW library</a></p>
  
  <p>I created a simple source code based on the site instructions:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #include &lt;glfw3.h&gt;
  
  // Need gl3.h for glGenVertexArrays() and glBindVertexArray()
  #include &lt;OpenGL/gl3.h&gt;
  
  // An array of 3 vectors which represents 3 vertices
  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,
  };
  
  #define printGlErr(func) err = glGetError(); if (err) fprintf(stderr, func " error: %u at line %d\n", err, __LINE__);
  GLuint err;
  
  int main(int argc, const char * argv[]) {
      if (!glfwInit()) {
          fprintf( stderr, "Failed to initialize GLFW\n" );
          return -1;
      }
  
      glfwWindowHint(GLFW_SAMPLES, 4);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL
  
      // Open a window and create its OpenGL context
      GLFWwindow* window;
      window = glfwCreateWindow(1024, 768, "Triangle", NULL, NULL);
      if (window == NULL) {
          fprintf(stderr, "Failed to open GLFW window.\n");
          glfwTerminate();
          return -1;
      }
      glfwMakeContextCurrent(window);
  
      // Ensure we can capture the escape key being pressed below
      glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
  
      // Init stuff
      GLuint VertexArrayID;
      glGenVertexArrays(1, &amp;VertexArrayID);
      glBindVertexArray(VertexArrayID);
  
      // This will identify our vertex buffer
      GLuint vertexbuffer;
  
      // Generate 1 buffer, put the resulting identifier in vertexbuffer
      glGenBuffers(1, &amp;vertexbuffer);
      printGlErr("glGenBuffers()");
  
      // The following commands will talk about our 'vertexbuffer' buffer
      glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
      printGlErr("glBindBuffer()");
  
      // Give our vertices to OpenGL.
      glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
      printGlErr("glBufferData()");
  
      do {
          // Draw stuff
          glEnableVertexAttribArray(0);
          glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
          glVertexAttribPointer(
                                0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
                                3,                  // size
                                GL_FLOAT,           // type
                                GL_FALSE,           // normalized?
                                0,                  // stride
                                (void*)0            // array buffer offset
                                );
          printGlErr("glVertexAttribPointer()");
  
          glDrawArrays(GL_TRIANGLES, 0, 3);
          printGlErr("glDrawArrays()");
  
          glDisableVertexAttribArray(0);
          printGlErr("glDisableVertexAttribArray()");
  
          // Swap buffers
          glfwSwapBuffers(window);
          glfwPollEvents();
      } while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &amp;&amp; glfwWindowShouldClose(window) == 0); // Check if the ESC key was pressed or the window was closed
  
      printf("Goodbye!\n");
      return(0);
  }
  </code></pre>
  
  <p>I can't seem to get the code to work. I'm getting a GL_INVALID_OPERATION on the <code>glDrawArrays()</code> function call.</p>
  
  <p>The code renders a black window on Mavericks and on Yosemite. This is my hardware specs: <a href="http://support.apple.com/kb/SP653" rel="nofollow noreferrer">http://support.apple.com/kb/SP653</a></p>
  
  <p>It does not crash, it exits on ESC, but nothing else happens (other than spamming the error code on the console). The results are the same using any of the 2 available video boards.</p>
  
  <p>Also, I'm compiling the source code using the following line on terminal:
  <code>gcc main.c -o triangle -framework OpenGl -framework Cocoa -framework IOKit -framework CoreVideo -I../glfw/include/GLFW -L../glfw/src -lglfw3</code></p>