My current code structure generates a maze using GL_LINES. I'm putting the vertex and index data into vertex buffer objects (GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER) during the initialization stage of my code.
my glBufferData commands are currently set to GL_STATIC_DRAW.
What I want to do is to have a keypress that lets me go back and reinitialize the entire maze. I have the code now that calls the initialize maze command on keypress, and it appears to work fine. I'm clearing the maze array, clearing the vertex array, and clearing the index array, and then regenerating all of that data (m_vertices.push_back, m_indices.push_back) and running the following lines again:
Code :glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glEnableClientState(GL_VERTEX_ARRAY); glGenBuffers(MAX_BUFFERS, &m_vbos); glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VERTEX_BUFFER]); //Bind the vertex buffer glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * m_vertices.size(), &m_vertices, GL_STATIC_DRAW); //Send the data to OpenGL glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbos[INDEX_BUFFER]); //Bind the index buffer glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * m_indices.size(), &m_indices, GL_STATIC_DRAW); //Send the data to OpenGL glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VERTEX_BUFFER]); glVertexPointer(3, GL_FLOAT, 0, 0);
And then it renders the new data properly
My question is...is it ok to just keep calling that block of code every time i want to regenerate? Or should I be destroying the buffers first and then recreating them with the above code? if I should be destroying them, what is the proper code and order to destroy or unallocate the buffers? I'm pretty new to this, so go easy