I want to change and update the vertices and indices of the 3D object.

I am new to openGL and I do not know if this the right place to ask this question.

I searched and read about that, and I found that I should bind the VAO and VBO and make that, but nothing changed in vertices and indices.

The vertices vector class type has the position, normal and uv coords and the vertices vector class type is int. I wonder how I can make changes to these two vectors when I translate or scale the model.

here is the code:

// Create buffers/arrays
glGenVertexArrays(1, &this->VAO);
glGenBuffers(1, &this->VBO);
glGenBuffers(1, &this->EBO);

// Load data into vertex buffers
glBindBuffer(GL_ARRAY_BUFFER, this->VBO);
// A great thing about structs is that their memory layout is sequential for all its items.
// The effect is that we can simply pass a pointer to the struct and it translates perfectly to a glm::vec3/2 array which
// again translates to 3/2 floats which translates to a byte array.
glBufferData(GL_ARRAY_BUFFER,this->vertices.size() * sizeof(vertex), &this->vertices[0], GL_STATIC_DRAW);

glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->indices.size() * sizeof(int), &this->indices[0], GL_STATIC_DRAW);

// Set the vertex attribute pointers
// Vertex Positions
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(vertex), (GLvoid*)0);
// Vertex Normals
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(vertex), (GLvoid*)offsetof(vertex, normal));
// Vertex Texture Coords
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(vertex), (GLvoid*)offsetof(vertex, uv));

  • 1
    \$\begingroup\$ You don't typically update the vertex data to update an object's transform. You update the model matrix (and subsequently, the MVP matrix), and pass it to the vertex shader to update the vertex. \$\endgroup\$ – Rish Feb 18 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.