2021-11-25 21:15:24 +00:00
|
|
|
//
|
|
|
|
// Created by SeanOMik on 7/2/2020.
|
|
|
|
// Github: https://github.com/SeanOMik
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SIMPLEENGINE_SQUARE_H
|
|
|
|
#define SIMPLEENGINE_SQUARE_H
|
|
|
|
|
|
|
|
#include <gl/glew.h>
|
|
|
|
#include <gl/gl.h>
|
|
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
|
|
|
#include "../../renderable.h"
|
|
|
|
#include "../../vertex.h"
|
|
|
|
|
|
|
|
#include "../../gfx/vbo.h"
|
|
|
|
#include "../../gfx/vao.h"
|
2021-11-27 18:52:48 +00:00
|
|
|
#include "../../gfx/texture.h"
|
2021-11-25 21:15:24 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace simpleengine::shapes_2d {
|
|
|
|
class Square : public simpleengine::Renderable {
|
|
|
|
private:
|
|
|
|
using super = simpleengine::Renderable;
|
|
|
|
private:
|
|
|
|
std::shared_ptr<GLuint> shader_program;
|
2021-11-27 18:52:48 +00:00
|
|
|
Texture& texture;
|
2021-11-25 21:15:24 +00:00
|
|
|
public:
|
2021-11-26 03:28:47 +00:00
|
|
|
std::vector<Vertex> vertices;
|
2021-11-25 21:15:24 +00:00
|
|
|
std::vector<GLuint> indicies;
|
|
|
|
gfx::VBO ebo;
|
|
|
|
gfx::VBO vbo;
|
|
|
|
gfx::VAO vao;
|
|
|
|
|
2021-11-27 18:52:48 +00:00
|
|
|
Square(std::shared_ptr<GLuint> shader_program, Texture& texture, std::vector<Vertex> vertices, std::vector<GLuint> indicies) :
|
2021-11-25 21:15:24 +00:00
|
|
|
super(nullptr), shader_program(shader_program), vertices(vertices), indicies(indicies),
|
|
|
|
ebo(gfx::VBO(GL_ELEMENT_ARRAY_BUFFER, false)), vbo(gfx::VBO(GL_ARRAY_BUFFER, false)),
|
2021-11-27 18:52:48 +00:00
|
|
|
texture(texture) {
|
2021-11-25 21:15:24 +00:00
|
|
|
|
|
|
|
vao.bind();
|
2021-11-26 03:28:47 +00:00
|
|
|
vbo.buffer(vertices.data(), 0, sizeof(Vertex) * vertices.size());
|
2021-11-25 21:15:24 +00:00
|
|
|
ebo.buffer(indicies.data(), 0, indicies.size() * sizeof(GLuint));
|
|
|
|
|
2021-11-26 03:28:47 +00:00
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, position));
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
|
|
|
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, color));
|
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
|
|
|
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, tex_coord));
|
|
|
|
glEnableVertexAttribArray(2);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
glBindVertexArray(0);
|
2021-11-25 21:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~Square() = default;
|
|
|
|
|
|
|
|
virtual void update(const float& delta_time) override {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void render(std::shared_ptr<GLFWwindow> target) override {
|
2021-11-27 18:52:48 +00:00
|
|
|
texture.bind();
|
|
|
|
|
2021-11-25 21:15:24 +00:00
|
|
|
glUseProgram(*shader_program);
|
|
|
|
|
|
|
|
vao.bind();
|
|
|
|
glDrawElements(GL_TRIANGLES, indicies.size(), GL_UNSIGNED_INT, 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //SIMPLEENGINE_TRIANGLE_H
|