I have a VBO and I instance it and a VAO in a Line drawing class called Line with a call to
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
that creates them before my do-while loop where the rendering occurs. Constructed like this
Line X= Line();
During the rendering loop I do a draw call from the same class function that I instanced like this.
X.draw(vec3 start ,vec3 end);
In the draw function I bind VAO and VBO and draw. Then I call
X.draw(vec3 start ,vec3 end);
again from the next line in my do-while loop. and a few more times. Each time it draws a line where I want without issue. But my question is, is it overwriting the VBO? or just pushing the new data in to the )index position and heaping up data behind it in the VBO with each call for a new line? And if so how long will it go on? It appears to concatenate the new vertex's with the old. But If I have a program that's using lines as bullets or something, I might get many instances of lines flying around and maybe I'm using the wrong methods and need to wipe the buffer or it gets overwritten with each new binding in the draw calls. My draw call looks like this for clarity.
int Line::draw(vec3 start, vec3 end){
glUseProgram(shaderProgram);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "MVP"), 1, GL_FALSE, &MVP[0][0]);
glUniform3fv(glGetUniformLocation(shaderProgram, "color"), 1, &lineColor[0]);
glLineWidth(4.0f);
vertices = {
start.x, start.y, start.z,
end.x, end.y, end.z
};
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*vertices.size(), vertices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3* sizeof(float), (void*)0);
glDrawArrays(GL_LINES, 0, 2);
glEnableVertexAttribArray(0);
return 0;
}