|
|
@ -2,19 +2,45 @@ |
|
|
|
#include <glm/glm.hpp> |
|
|
|
#include <glm/glm.hpp> |
|
|
|
#include <glm/gtc/matrix_transform.hpp> |
|
|
|
#include <glm/gtc/matrix_transform.hpp> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "GLFW/glfw3.h" |
|
|
|
#include "renderer.hpp" |
|
|
|
#include "renderer.hpp" |
|
|
|
#include "shaders.hpp" |
|
|
|
#include "shaders.hpp" |
|
|
|
|
|
|
|
|
|
|
|
namespace Renderer { |
|
|
|
namespace Renderer { |
|
|
|
|
|
|
|
|
|
|
|
Renderer3D::Renderer3D() { |
|
|
|
// Renderer3D
|
|
|
|
// TODO: Make more OOP
|
|
|
|
Renderer3D::Renderer3D(GLFWwindow* win) { |
|
|
|
|
|
|
|
window = win;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setFOV(DEFAULT_FOV); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Renderer3D::Renderer3D(GLFWwindow* win, std::vector<RenderObject> ROs) : Renderer3D(win) { |
|
|
|
|
|
|
|
renderObjects = ROs; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Renderer3D::setFOV(float fov) { |
|
|
|
|
|
|
|
int width, height; |
|
|
|
|
|
|
|
glfwGetWindowSize(window, &width, &height); |
|
|
|
|
|
|
|
projectionTransform = glm::perspective(glm::radians(fov), (float)width / (float)height, NEAR_PLANE, FAR_PLANE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Renderer3D::setCamera(glm::vec3 pos) { |
|
|
|
|
|
|
|
cameraTransform = glm::translate(cameraTransform, pos);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Renderer3D::Renderer3D(std::vector<RenderObject> ROs) : Renderer3D() { |
|
|
|
void Renderer3D::render() { |
|
|
|
RenderObjects = ROs; |
|
|
|
for ( RenderObject ro: renderObjects )
|
|
|
|
|
|
|
|
ro.render(window, cameraTransform, projectionTransform); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RenderObject
|
|
|
|
|
|
|
|
RenderObject::RenderObject() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RenderObject::render(GLFWwindow* win, glm::mat4 cameraTransform, glm::mat4 projectionTransform) {} |
|
|
|
|
|
|
|
|
|
|
|
void Obj2D::transform(glm::mat4 T) { |
|
|
|
void Obj2D::transform(glm::mat4 T) { |
|
|
|
shader.setMat4("model", T); |
|
|
|
shader.setMat4("model", T); |
|
|
|
} |
|
|
|
} |
|
|
@ -49,20 +75,17 @@ namespace Renderer { |
|
|
|
Obj2D::Obj2D(unsigned int indices[], unsigned int icount, float verts[], unsigned int vcount)
|
|
|
|
Obj2D::Obj2D(unsigned int indices[], unsigned int icount, float verts[], unsigned int vcount)
|
|
|
|
: shader(VERT_SHADER_SRC_FILE, FRAG_SHADER_SRC_FILE) { |
|
|
|
: shader(VERT_SHADER_SRC_FILE, FRAG_SHADER_SRC_FILE) { |
|
|
|
|
|
|
|
|
|
|
|
// Vertex buffer object
|
|
|
|
|
|
|
|
glGenBuffers(1, &VBO); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Vertex Array Object
|
|
|
|
// Vertex Array Object
|
|
|
|
glGenVertexArrays(1, &VAO); // gen the VAO
|
|
|
|
glGenVertexArrays(1, &VAO); // gen the VAO
|
|
|
|
glBindVertexArray(VAO); // bind it
|
|
|
|
glBindVertexArray(VAO); // bind it
|
|
|
|
|
|
|
|
|
|
|
|
// Copy verts into buffer
|
|
|
|
// Copy the verts into the buffer
|
|
|
|
|
|
|
|
glGenBuffers(1, &VBO); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VBO); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, VBO); |
|
|
|
glBufferData(GL_ARRAY_BUFFER, vcount, verts, GL_DYNAMIC_DRAW); // for moving stuff
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, vcount, verts, GL_DYNAMIC_DRAW); // for moving stuff
|
|
|
|
//glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy the indices for the verts into another buffer
|
|
|
|
glGenBuffers(1, &EBO); |
|
|
|
glGenBuffers(1, &EBO); |
|
|
|
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); |
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, icount, indices, GL_STATIC_DRAW); |
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, icount, indices, GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|