Advertisement
gravityio

Model.cpp

Feb 9th, 2023
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. Model::Model(const float data[], const unsigned int indices[])
  2. {
  3.   LOG("MAKING MODEL");
  4.   // We create a Vertex Buffer Object (Storage for Vertex Data)
  5.   // We create Vertex Array Object (Storage for VBO, EBO, VAP)
  6.   // We create Element Buffer Object (Storage for Indices on how the triangles are formed from the vertices)
  7.   glGenVertexArrays(1, &VAO);
  8.   glGenBuffers(1, &VBO);
  9.   glGenBuffers(1, &EBO);
  10.  
  11.   // We set the current state to run executions on this VAO
  12.   glBindVertexArray(VAO);
  13.  
  14.   // We set the current state inside the VAO to run executions for a Buffer, saying its an array buffer for our VBO
  15.   glBindBuffer(GL_ARRAY_BUFFER, VBO);
  16.   // 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
  17.   // GL_STATIC_DRAW means we will only assign them once and not change them
  18.   // GL_STATIC_READ means
  19.   glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
  20.  
  21.   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
  22.   glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
  23.  
  24.   glEnableVertexAttribArray(0);
  25.   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
  26.   glEnableVertexAttribArray(1);
  27.   glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
  28.  
  29.   glBindVertexArray(0);
  30. }
  31.  
  32. Model::~Model()
  33. {
  34.   glDeleteVertexArrays(1, &VAO);
  35.   glDeleteBuffers(1, &VBO);
  36.   glDeleteBuffers(1, &EBO);
  37. }
  38.  
  39. void Model::render()
  40. {
  41.   glBindVertexArray(VAO);
  42.   glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
  43.   glBindVertexArray(0);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement