#include #include deerith::mesh_2d_t::mesh_2d_t( const glm::vec2 *vertices, std::size_t vertex_count, const unsigned int *indices, std::size_t index_count) : index_count(index_count) { glGenVertexArrays(1, &vao); glGenBuffers(1, &vbo); glGenBuffers(1, &ebo); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData( GL_ARRAY_BUFFER, vertex_count * sizeof(glm::vec2), vertices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData( GL_ELEMENT_ARRAY_BUFFER, index_count * sizeof(unsigned int), indices, GL_STATIC_DRAW); // Position: vec2 glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), nullptr); glEnableVertexAttribArray(0); glBindVertexArray(0); } deerith::mesh_2d_t::~mesh_2d_t() { glDeleteVertexArrays(1, &vao); glDeleteBuffers(1, &vbo); glDeleteBuffers(1, &ebo); } void deerith::mesh_2d_t::bind() const { glBindVertexArray(vao); } void deerith::mesh_2d_t::draw() const { glBindVertexArray(vao); glDrawElements( GL_TRIANGLES, static_cast(index_count), GL_UNSIGNED_INT, nullptr); } deerith::mesh_3d_t::mesh_3d_t( const glm::vec3 *vertices, std::size_t _vertex_count, const unsigned int *indices, std::size_t _index_count) : index_count(_index_count), vertex_count(_vertex_count) { glGenVertexArrays(1, &vao); glGenBuffers(1, &vbo); glGenBuffers(1, &ebo); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData( GL_ARRAY_BUFFER, vertex_count * sizeof(glm::vec3), vertices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData( GL_ELEMENT_ARRAY_BUFFER, index_count * sizeof(unsigned int), indices, GL_STATIC_DRAW); // Position: vec2 glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr); glEnableVertexAttribArray(0); glBindVertexArray(0); } deerith::mesh_3d_t::~mesh_3d_t() { glDeleteVertexArrays(1, &vao); glDeleteBuffers(1, &vbo); glDeleteBuffers(1, &ebo); } void deerith::mesh_3d_t::bind() const { glBindVertexArray(vao); } void deerith::mesh_3d_t::draw() const { glBindVertexArray(vao); glDrawElements( GL_TRIANGLES, static_cast(index_count), GL_UNSIGNED_INT, nullptr); } void deerith::mesh_3d_t::draw_lines() const { glBindVertexArray(vao); glDrawArrays(GL_LINES, 0, vertex_count); }