title: Why glDrawArrays fails with GL_INVALID_OPERATION?
body: <p>I am using OpenGL to draw a rectangle, and I am doing this with golang.</p>
  
  <p>I am not using red, green, blue argument for now.</p>
  
  <pre><code>var vertices = []float64{ 
      -1.0, -1.0,  0.0,   // V1 - bottom left 
      -1.0,  1.0,  0.0,   // V2 - top left 
      1.0, -1.0,  0.0,    // V3 - bottom right 
      1.0,  1.0,  0.0,    // V4 - top right 
  }
  
  func DisplayWrite(red []byte, green []byte, blue []byte) {
      const GL_TRUE = 1
      const GL_FALSE = 0
      const GL_FLOAT = 0x1406
      const GL_VERTEX_ARRAY = 0x8074
      const GL_TRIANGLE_STRIP = 0x0005
      C.glLoadIdentity();
      chkGlErr("glLoadIdentity")
      C.glTranslatef(0.0, 0.0, -5.0);
      chkGlErr("glTranslatef")
      C.glEnableClientState(GL_VERTEX_ARRAY);
      chkGlErr("glEnableClientState")
      C.glColor4f(1.0, 1.0, 1.0, 1.0);
      chkGlErr("glColor4f")
      C.glVertexPointer(3, GL_FLOAT, 0, (unsafe.Pointer)(&amp;vertices));
      chkGlErr("glVertexPointer")
      C.glDrawArrays(GL_TRIANGLE_STRIP, 0, (C.GLsizei)(len(vertices) / 3));
      chkGlErr("glDrawArrays")
      C.glDisableClientState(GL_VERTEX_ARRAY);
      chkGlErr("glDisableClientState")
      const GL_UNSIGNED_BYTE = 0x1401
      //C.glDrawPixels(Width, Height, GL_RED, GL_UNSIGNED_BYTE, &amp;red[0])
      //C.glDrawPixels(Width, Height, GL_GREEN, GL_UNSIGNED_BYTE, &amp;green[0])
      //C.glDrawPixels(Width, Height, GL_GREEN, GL_UNSIGNED_BYTE, &amp;blue[0])
  }
  </code></pre>
  
  <p>Problem is when I call glDrawArrays like this:</p>
  
  <pre><code>C.glDrawArrays(GL_TRIANGLE_STRIP, 0, (C.GLsizei)(len(vertices) / 3));
  </code></pre>
  
  <p>It draws nothing and error is GL_INVALID_OPERATION.
  Is something wrong with the way I draw something?</p>
  
  <p>This is setup part:</p>
  
  <pre><code>func DisplayInit() DispInitStatus {
      //(EGL and OpenGL ES initialization codes...)
  
      C.glViewport(0, 0, (C.GLsizei)(dWidth), (C.GLsizei)(dHeight));
      chkGlErr("glViewport")
      C.glMatrixMode(GL_PROJECTION);
      chkGlErr("glMatrixMode")
      C.glLoadIdentity();
      chkGlErr("glLoadIdentity")
  
      makeFrustum(45.0, (float64)(dWidth) / (float64)(dHeight), 0.1, 100.0)
  
      C.glMatrixMode(GL_MODELVIEW);
      chkGlErr("glMatrixMode")
      C.glLoadIdentity();
      chkGlErr("glLoadIdentity")
  
      //C.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
      //chkGlErr("glHint")
      C.glClearColor(1.0, 0.0, 0.0, 1.0);
      chkGlErr("glClearColor")
      C.glClear(GL_COLOR_BUFFER_BIT);
      chkGlErr("glClear")
      fmt.Println("EGL/GLES is now ready")
      return Disp_Ok
      //No error with these.
  }
  </code></pre>
  
  <p>And main function</p>
  
  <p>(DisplayUpdate does glFlush and eglSwapBuffers. It works with no problem.)</p>
  
  <pre><code>func main() {
      runtime.LockOSThread()
      DisplayInit()
      red := make([]byte, dWidth*dHeight)
      gre := make([]byte, dWidth*dHeight)
      blu := make([]byte, dWidth*dHeight)
      DisplayWrite(red, gre, blu)
      DisplayUpdate()
      for {
      }
  }
  </code></pre>
  
  <p>I googled and found this:</p>
  
  <p><a href="https://stackoverflow.com/questions/13051587/why-does-opengls-gldrawarrays-fail-with-gl-invalid-operation-under-core-profi">Why does OpenGL&#39;s glDrawArrays() fail with GL_INVALID_OPERATION under Core Profile 3.2, but not 3.3 or 4.2?</a></p>
  
  <p>And I tried using runtime.LockOSThread() like above, but still doesn't work.</p>
  
  <p>ADD: Added makeFrustum.</p>
  
  <pre><code>func makeFrustum(fovY, aspectRatio, front, back float64) {
      tangent := math.Tan(fovY / 2 * (3.14159265 / 180.0));   // tangent of half fovY
      height := front * tangent;          // half height of near plane
      width := height * aspectRatio;      // half width of near plane
      // params: left, right, bottom, top, near, far
      C.glFrustumf((C.GLfloat)(-width), (C.GLfloat)(width), (C.GLfloat)(-height), (C.GLfloat)(height), (C.GLfloat)(front), (C.GLfloat)(back));
      chkGlErr("glFrustumf")
  }
  </code></pre>
  
  <p>This causes no error, too.</p>
  
  <p>This does same thing as gluPerspective.</p>
  
  <p><a href="https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml" rel="nofollow noreferrer">https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml</a></p>