Vertex array objects and black screen of death

I have problems with the following pseudo code. It works when not defining USEVAO, but as soon as I define USEVAO it stops working.


Init() {
  glEnableVertexAttribArray
  glGenVertexArrays(1, &vao)
  glBindVertexArray(vao)
  glGenBuffers
  glBindBuffer(GL_ARRAY_BUFFER)
  glBufferData(GL_ARRAY_BUFFER)
  glVertexAttribPointer
  glBindVertexArray(0)
}

Draw() {
#ifdef USEVAO
  glBindVertexArray(vao)
#else
  glBindVertexArray(0)
  glBindBuffer(GL_ARRAY_BUFFER)
  glVertexAttribPointer
#endif
  glDrawArrays
}

Using glGetVertexAttribPointerv() immediately before glDrawArrays(), I have verified that the byte offset is correctly set-up (works with and without USEVAO defined). There is probably some simple mistake, but having spent a couple of days I am becoming desperate. This is not the only draw function I am using, maybe there is an interdependency I didn’t know about. I am using VAOs in other places. Apart from glGetVertexAttribPointerv, are there other ways I can read out the stored state of the vertex array object?

If I enable both branches of the #ifdef, it still does not work.

Calling glEnableVertexAttribArray affects the currently bound VAO, so you are not enabling the attribute for the generated vao.

Thanks, that fixed it!