I want to avoid repeating the following code many times since I use plenty VBOs:
glBindBuffer(GL_ARRAY_BUFFER, VBOs[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices1), vertices1, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, VBOs[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices2), vertices2, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, VBOs[2]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices3), vertices3, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, VBOs[3]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices4), vertices4, GL_STATIC_DRAW);
I tried to simplify this code with a cycle. Here is what I tried to do:
std::string aux = "vertices";
std::string aux2;
int aux3;
std::string aux4;
const void* aux5;
for (int i = 0; i <= 13; i++) {
aux3 = i++;
aux4 = std::to_string(aux3);
aux2 = aux + aux4;
aux5 = aux2.c_str();
glBindBuffer(GL_ARRAY_BUFFER, VBOs[i]);
glBufferData(GL_ARRAY_BUFFER, sizeof(aux2), aux5, GL_STATIC_DRAW);
}
It didn't work out. It still shows a figure with the last color I used but doesn't paint the other figures. Is there a way to make that cycle work or should I continue repeating the code like above? Thanks for the help.
I also tried simplifying the VAOs section in the code with a cycle and it worked. Here is how I did it:
glGenVertexArrays(14, VAOs);
for (int i = 0; i <= 13; i++) {
glBindVertexArray(VAOs[i]);
glBindBuffer(GL_ARRAY_BUFFER, VBOs[i]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
}