// // Created by SeanOMik on 7/2/2020. // Github: https://github.com/SeanOMik // #ifndef SIMPLEENGINE_TRIANGLE_H #define SIMPLEENGINE_TRIANGLE_H #include #include #include #include #include "../../renderable.h" #include "../../vertex.h" #include "../../gfx/vbo.h" #include "../../gfx/vao.h" #include "simpleengine/gfx/vao.h" #include namespace simpleengine::shapes_2d { class Triangle : public simpleengine::Renderable { private: using super = simpleengine::Renderable; private: std::shared_ptr shader_program; public: std::vector vertices; gfx::VBO vbo; gfx::VAO vao; Triangle(std::shared_ptr shader_program, std::vector vertices) : super(nullptr), shader_program(shader_program), vertices(vertices), vbo(gfx::VBO(GL_ARRAY_BUFFER, false)), vao(gfx::VAO()) { vao.bind(); vbo.buffer(vertices.data(), 0, vertices.size() * sizeof(float) * 3); // 3 floats are in each "row" of the vector. vao.enable_attrib(vbo, 0, vertices.size(), GL_FLOAT, 3 * sizeof(float), 0); } virtual ~Triangle() = default; virtual void update(const float& delta_time) override { } virtual void render(std::shared_ptr target) override { glUseProgram(*shader_program); vao.bind(); glDrawArrays(GL_TRIANGLES, 0, 3); } }; } #endif //SIMPLEENGINE_TRIANGLE_H