title: Can't draw anything in openGL using GLEW (mac,c++)
body: <p>I am trying to learn OpenGL programming in c++, using <a href="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/" rel="nofollow">This tutorial</a>. i  am using a macbook pro, running OSX-Yosemite version 10.10.3. My openGL version is 3.3.</p>
  
  <p>I am using the libraries GLFW, and GLEW.</p>
  
  <p>I am compiling (and linking) my code from my terminal using this command:<code>g++ triangleTest.cpp -o triangleTest -lglfw3 -lglew -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo</code> (i am not writing in Xcode).</p>
  
  <p>The goal of this program is to make a white triangle on a black background, the code looks like this:</p>
  
  <pre><code>// Include standard headers
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include&lt;iostream&gt;
  #include &lt;GL/glew.h&gt;
  #include&lt;GLFW/glfw3.h&gt;
  GLFWwindow* window;
  
  // 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, 1.0f,
  };
  
  int main(){
  
      // Initialise GLFW
      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); 
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  
  
      std::cout&lt;&lt;"GLFW3 initialized\n";
  
  
      window = glfwCreateWindow(640, 480, "I am a triangle", NULL, NULL);
  
       if (!window)
       {
           glfwTerminate();
           std::cout&lt;&lt;"Window initialization failed\n";
          return 1;   
       }
  
      std::cout&lt;&lt;"Window initialized\n";
  
      glfwMakeContextCurrent(window);
  
      if (glewInit() != GLEW_OK) {
          std::cout&lt;&lt;"Failed to initialize GLEW try again\n";
          return 1;
      }
  
  
      // This will identify our vertex buffer
      GLuint vertexbuffer;
      // Generate 1 buffer, put the resulting identifier in vertexbuffer
      glGenBuffers(1, &amp;vertexbuffer); 
      // The following commands will talk about our 'vertexbuffer' buffer
      glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
      // Give our vertices to OpenGL.
      glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
  
  
  
  
  
  
      glfwSwapInterval(1);
  
       while (!glfwWindowShouldClose(window)){
  
          // Clear the screen
          glClear( GL_COLOR_BUFFER_BIT );
  
          glEnableVertexAttribArray(0);
          glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
          glVertexAttribPointer(
              1,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
              3,                  // size
              GL_FLOAT,           // type
              GL_TRUE,           // normalized?
              0,                  // stride
              (void*)0            // array buffer offset
          );
  
          // Draw the triangle !
          glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -&gt; 1 triangle
  
          glDisableVertexAttribArray(0);
  
          glfwSwapBuffers(window);
          glfwPollEvents();
       }
  
  
      glfwTerminate();    
  }
  </code></pre>
  
  <p>The code is compiled and run (from the terminal), and a black window with no triangle, but the correct name and size apears. The window works perfectly, and can be moved around and closed like it is suposed to, but the triangle is not drawn.</p>