title: How to set up vertex attributes in OpenGL?
body: <p>I am trying to create a VBO for a simple rectangle. The GL is set up to use the core profile (GL: 3.2, GLSL: 1.5, inside an NSView in Cocoa).</p>
  
  <p>I spent hours trying to figure out how to draw a simple rectangle in OpenGL. It seems really hard to find any decent tutorials on the core profile. The best I could find was <a href="http://en.wikipedia.org/wiki/Vertex_Buffer_Object" rel="nofollow">this tutorial</a>.</p>
  
  <p>I adapted it to my needs and came up with the following code:</p>
  
  <pre><code>GLfloat vertices[] = { 1.0, -1.0, 1.0,
                         1.0,  1.0, 1.0,
                        -1.0,  1.0, -1.0,
                        -1.0, -1.0, -1.0 };
  glGenBuffers(1, &amp;vertexVBO);
  glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
  glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*3*4, vertices, GL_STATIC_DRAW);
  glVertexAttribPointer(VERTEX_POS, 3, GL_FLOAT, GL_FALSE, 0, 0); // VERTEX_POS = 0
  glEnableVertexAttribArray(VERTEX_POS); // fails
  </code></pre>
  
  <p>However, this is throwing an error when calling <code>glEnableVertexAttribArray</code>: <code>INVALID_OPERATION</code>. <a href="http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml" rel="nofollow">The documentation</a> suggests that this error is produced if the aforementioned call is made between a <code>glBegin</code> and <code>glEnd</code>. This is not the case. I mean, as far as I know, <code>glBegin</code> and <code>glEnd</code> are not even supported in the core profile.</p>
  
  <p>Thus, I am at a loss. How can I draw this stupid rectangle (or at least initialize it)?</p>