Create a VAO and VBO with glGenVertexArrays and glGenBuffers
Create a VAO and VBO with glGenVertexArrays and glGenBuffers in OpenGL 3.3 core, bind the VAO first, then fill the buffer with a triangle.
This is how a core-profile OpenGL 3.3 program stores its first mesh. The core profile has no default vertex array object, so drawing without one fails; create the VAO first and bind it, because the buffer binding made next is recorded inside it.
GLuint vao, vbo;
float verts[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f,
};
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof verts, verts, GL_STATIC_DRAW);
printf("vao=%u vbo=%u\n", vao, vbo);vao=1 vbo=1The two names are numbered per object type, so both are 1 on a fresh context; the exact values depend on the driver. glGenVertexArrays and glGenBuffers only reserve names, and the object is not created until the first bind, as the glGenBuffers reference page describes. GL_ARRAY_BUFFER itself is global state, not part of the VAO, so the attribute pointers set up afterwards are what the VAO remembers.
Nothing here draws yet: you still need glVertexAttribPointer and a shader program. Before OpenGL 3.0 there is no glGenVertexArrays at all.