2021-11-21 06:23:53 +00:00
|
|
|
//
|
|
|
|
// Created by SeanOMik on 7/2/2020.
|
|
|
|
// Github: https://github.com/SeanOMik
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SIMPLEENGINE_TRIANGLE_H
|
|
|
|
#define SIMPLEENGINE_TRIANGLE_H
|
|
|
|
|
|
|
|
#include <gl/glew.h>
|
|
|
|
#include <gl/gl.h>
|
|
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
2021-11-25 21:15:24 +00:00
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
2021-11-21 06:23:53 +00:00
|
|
|
#include "../../renderable.h"
|
2021-11-25 21:15:24 +00:00
|
|
|
#include "../../vertex.h"
|
|
|
|
|
|
|
|
#include "../../gfx/vbo.h"
|
|
|
|
#include "../../gfx/vao.h"
|
|
|
|
#include "simpleengine/gfx/vao.h"
|
|
|
|
|
|
|
|
#include <vector>
|
2021-11-21 06:23:53 +00:00
|
|
|
|
|
|
|
namespace simpleengine::shapes_2d {
|
|
|
|
class Triangle : public simpleengine::Renderable {
|
|
|
|
private:
|
|
|
|
using super = simpleengine::Renderable;
|
|
|
|
private:
|
|
|
|
std::shared_ptr<GLuint> shader_program;
|
|
|
|
public:
|
2021-11-25 21:15:24 +00:00
|
|
|
std::vector<glm::vec3> vertices;
|
|
|
|
gfx::VBO vbo;
|
|
|
|
gfx::VAO vao;
|
2021-11-21 06:23:53 +00:00
|
|
|
|
2021-11-25 21:15:24 +00:00
|
|
|
Triangle(std::shared_ptr<GLuint> shader_program, std::vector<glm::vec3> vertices) : super(nullptr),
|
|
|
|
shader_program(shader_program), vertices(vertices), vbo(gfx::VBO(GL_ARRAY_BUFFER, false)),
|
|
|
|
vao(gfx::VAO()) {
|
2021-11-21 06:23:53 +00:00
|
|
|
|
2021-11-25 21:15:24 +00:00
|
|
|
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);
|
2021-11-21 06:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~Triangle() = default;
|
|
|
|
|
|
|
|
virtual void update(const float& delta_time) override {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void render(std::shared_ptr<GLFWwindow> target) override {
|
|
|
|
glUseProgram(*shader_program);
|
2021-11-25 21:15:24 +00:00
|
|
|
|
|
|
|
vao.bind();
|
2021-11-21 06:23:53 +00:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //SIMPLEENGINE_TRIANGLE_H
|