OpenGL updating vertex array / buffer

When I first add several vertices to the buffer, these are the corresponding functions that I call

    // Create and bind the object Vertex Array Object:
    glGenVertexArrays(1, &_vao);
    glBindVertexArray(_vao);

    // Create and load vertex data into a Vertex Buffer Object:
    glGenBuffers(1, &_vbo);
    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[0], GL_STATIC_DRAW);

    // Tells OpenGL that there is vertex data in this buffer object and what form that vertex data takes:

    // Obtain attribute handles:
    _posAttrib = glGetAttribLocation(program, "position");
    glEnableVertexAttribArray(_posAttrib);
    glVertexAttribPointer(_posAttrib, // attribute handle
                          4,          // number of scalars per vertex
                          GL_FLOAT,   // scalar type
                          GL_FALSE,
                          0,
                          0);

    // Unbind vertex array:
    glBindVertexArray(0);

But later in my program I want to add some more vertices.

I do it as follows (as part of a separate function:

add_vertices(x,y); //adds the necessary vertices to the vector. 
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, (TRIANGLE_AMOUNT+1)*4*_number_of_circles * sizeof(float), &vertices[0], GL_STATIC_DRAW);

Assuming the funk size in glBufferData's second argument is fine, did I miss something? Are there any other OpenGL features that require a call?

I don't get any errors, but when I try to draw additional shapes with new vertices by going through glDrawArrays with different subsets of vertices, nothing happens.

I hope this is semi-coherent ... let me know if there is any information that I have not provided.

Greetings.

+4
1

OpenGL - , :

vbo. :

glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, (TRIANGLE_AMOUNT+1)*4*_number_of_circles * sizeof(float),
    &vertices[0], GL_STATIC_DRAW);

glGenerateBuffers ( ) VAO .

Sidenote: .

+1

Source: https://habr.com/ru/post/1615028/


All Articles