Hi,
Recently I made a simple OpenGL program that works.
Today, I decided to copy this code in another new project, in order to re-use it.
The surprise is that this same code is not working.
// Create the VAOs used for the update and render passes
glGenVertexArrays(2, update_vao);
glGenVertexArrays(2, render_vao);
// Two buffers for each of position and velocity
glGenBuffers(2, position_buffer);
// Setup Update VAO 1
glBindVertexArray(update_vao[0]);
glBindBuffer(GL_ARRAY_BUFFER, position_buffer[0]);
glBufferData(GL_ARRAY_BUFFER, 2*positions.size() * sizeof(GL_FLOAT), positions.constData(), GL_DYNAMIC_COPY);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
// Setup Update VAO 2
glBindVertexArray(update_vao[1]);
glBindBuffer(GL_ARRAY_BUFFER, position_buffer[1]);
glBufferData(GL_ARRAY_BUFFER, 2*positions.size() * sizeof(GL_FLOAT), NULL, GL_DYNAMIC_COPY);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
// Setup Render VAOs
for (int i = 0; i < 2; i++)
{
glBindVertexArray(render_vao[i]);
glBindBuffer(GL_ARRAY_BUFFER, position_buffer[i]);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elem_array);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, elements.size() * sizeof(GL_FLOAT), elements.constData(), GL_STATIC_DRAW);
}
// Setup position and velocity TBOs
glGenTextures(2, position_tbo);
// Done with VAOs
glBindVertexArray(0);
// Set up TBOs
for (int i = 0; i < 2; i++)
{
glBindTexture(GL_TEXTURE_BUFFER, position_tbo[i]);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, position_buffer[i]);
}
I am having exceptions regarding the glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, flock_position[i]) ? I really don’t understand why? Maybe it is because I did not clean up everything after my rendering was done.
Here is the content of the destructor of my class :
glDeleteTextures(2,position_tbo);
glDeleteVertexArrays(2,update_vao);
glDeleteVertexArrays(2,render_vao);
glDeleteBuffers(2,position_buffer);
I never heard of a glDeleteTexBuffer and in this case the buffer I am binding to the TexBuffer is position_buffer.
Right now, If I run the first program, it works,
If I run the copy of the first program I have an exception (for memory allocation).