I am using GLEW to create an OpenGL context and "standard" win32 to create the window.
If I set up my VBO and VAO (both global variables) every frame then my geometry renders correctly. both program and positions are global and set before this loop happens.
while (!done)
{
PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
if (msg.message == WM_QUIT)
done = true;
else
{
glClear(GL_COLOR_BUFFER_BIT);
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);
glBindVertexArray(vao);
glVertexAttribBinding(0, vao);
glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(glm::vec4));
glVertexArrayAttribFormat(vao, 0, 4, GL_FLOAT, GL_FALSE, 0);
glEnableVertexAttribArray(0);
glUseProgram(program);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
glUseProgram(0);
SwapBuffers(g_HDC);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
However, I want initialise the VBO/VAO outside of the render block and instead bind the VAO every frame. Here is what I have currently but I still cannot get it to work. All that is rendered is a black screen.
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);
glBindVertexArray(vao);
glVertexAttribBinding(0, vao);
glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(glm::vec4));
glVertexArrayAttribFormat(vao, 0, 4, GL_FLOAT, GL_FALSE, 0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
while (!done)
{
PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
if (msg.message == WM_QUIT)
done = true;
else
{
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(program);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
glUseProgram(0);
SwapBuffers(g_HDC);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
I am under the impression that once the buffer data has been set it is permanent until explicitly deleted? Am I missing something here?
All help is much appreciated.