Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Model::Model(const float data[], const unsigned int indices[])
- {
- LOG("MAKING MODEL");
- // We create a Vertex Buffer Object (Storage for Vertex Data)
- // We create Vertex Array Object (Storage for VBO, EBO, VAP)
- // We create Element Buffer Object (Storage for Indices on how the triangles are formed from the vertices)
- glGenVertexArrays(1, &VAO);
- glGenBuffers(1, &VBO);
- glGenBuffers(1, &EBO);
- // We set the current state to run executions on this VAO
- glBindVertexArray(VAO);
- // We set the current state inside the VAO to run executions for a Buffer, saying its an array buffer for our VBO
- glBindBuffer(GL_ARRAY_BUFFER, VBO);
- // We set the data of the binded VBO with the vertices stating it's an array, how much vertex data there is, the actual data, and how we're going to use the vertices
- // GL_STATIC_DRAW means we will only assign them once and not change them
- // GL_STATIC_READ means
- glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
- glEnableVertexAttribArray(1);
- glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
- glBindVertexArray(0);
- }
- Model::~Model()
- {
- glDeleteVertexArrays(1, &VAO);
- glDeleteBuffers(1, &VBO);
- glDeleteBuffers(1, &EBO);
- }
- void Model::render()
- {
- glBindVertexArray(VAO);
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
- glBindVertexArray(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement