Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Mesh.h"
- #include <glm\gtc\matrix_transform.hpp>
- #include <glm\gtc\type_ptr.hpp>
- #define STB_IMAGE_IMPLEMENTATION
- #include <stb_image.h>
- Mesh::Mesh()
- {
- glGenVertexArrays(1, &m_vertexArrayObject);
- glGenBuffers(NUMBER_OF_BUFFERS, m_buffers);
- }
- Mesh::~Mesh()
- {
- glDeleteVertexArrays(1, &m_vertexArrayObject);
- glDeleteBuffers(NUMBER_OF_BUFFERS, m_buffers);
- }
- void Mesh::addData(const glm::vec3& vertexPosition, const glm::vec2& textureCoordinates)
- {
- m_vertexPositions.push_back(vertexPosition.x);
- m_vertexPositions.push_back(vertexPosition.y);
- m_vertexPositions.push_back(vertexPosition.z);
- m_textureCoordinates.push_back(textureCoordinates.x);
- m_textureCoordinates.push_back(textureCoordinates.y);
- }
- void Mesh::upload()
- {
- glBindVertexArray(m_vertexArrayObject);
- /* Vertex Buffer*/
- glBindBuffer(GL_ARRAY_BUFFER, m_buffers[VERTEX_BUFFER]);
- glBufferData(GL_ARRAY_BUFFER, m_vertexPositions.size() * sizeof(m_vertexPositions.size()), m_vertexPositions.data(), GL_STATIC_DRAW);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
- glEnableVertexAttribArray(0);
- /* Texture buffer */
- glBindBuffer(GL_ARRAY_BUFFER, m_buffers[TEXTURE_BUFFER]);
- glBufferData(GL_ARRAY_BUFFER, m_textureCoordinates.size() * sizeof(m_textureCoordinates.size()), m_textureCoordinates.data(), GL_STATIC_DRAW);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
- glEnableVertexAttribArray(1);
- /* Index Buffer */
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffers[INDEX_BUFFER]);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indices.size() * sizeof(m_indices.size()), m_indices.data(), GL_STATIC_DRAW);
- glBindVertexArray(0);
- }
- void Mesh::clear()
- {
- m_vertexPositions.clear();
- m_textureCoordinates.clear();
- m_indices.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement