// // Created by karl on 07.01.20. // #ifndef ECSGAME_MESH_H #define ECSGAME_MESH_H #include #include #include struct Mesh { explicit Mesh(std::vector vertices) : vertices(vertices), vertex_count(vertices.size() / 5) { glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(&vertices), &vertices, GL_STATIC_DRAW); // position attribute glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // texture coord attribute glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); glEnableVertexAttribArray(1); } void render() { glBindVertexArray(VAO); glDrawArrays(GL_TRIANGLES, 0, vertex_count); } private: unsigned int VBO; unsigned int VAO; unsigned int vertex_count; /// Vertices in the format x, y, z, u, v std::vector vertices; }; #endif //ECSGAME_MESH_H