Lightweight OpenGL 3D Renderer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Euclid/headers/renderer.hpp

66 lines
1.6 KiB

#pragma once
#include <glm/fwd.hpp>
2 years ago
#include <glm/glm.hpp>
2 years ago
#include <vector>
2 years ago
#include "shaders.hpp"
#include "textures.hpp"
2 years ago
#include "GLFW/glfw3.h"
#define VERTEX_ATTRIB_PTR_SIZE 8 * sizeof(float)
#define VERT_SHADER_SRC_FILE "shaders/vertex.glsl"
#define FRAG_SHADER_SRC_FILE "shaders/fragment.glsl"
2 years ago
#define DEFAULT_FOV 45.0f
#define NEAR_PLANE 0.1f
#define FAR_PLANE 100.0f
namespace Renderer {
2 years ago
class RenderObject {
public:
2 years ago
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
RenderObject(std::vector<float> verts, std::vector<unsigned int> indices);
2 years ago
void render(GLFWwindow* win, glm::mat4 cameraTransform, glm::mat4 projectionTransform);
2 years ago
void setRotation(float angle, glm::vec3 axis);
2 years ago
void transform(glm::mat4 T);
void preRenderHook();
2 years ago
private:
2 years ago
Shaders::Shader shader;
unsigned int EBO;
unsigned int VBO;
unsigned int VAO;
std::vector<float> vertsVec;
std::vector<unsigned int> indicesVec;
2 years ago
};
2 years ago
class Renderer3D {
public:
2 years ago
Renderer3D(GLFWwindow* win);
Renderer3D(GLFWwindow* win, std::vector<RenderObject> ROs);
2 years ago
void setCamera(glm::vec3 pos);
void setFOV(float deg);
2 years ago
void spawnObject(RenderObject ro);
2 years ago
void render();
2 years ago
private:
2 years ago
std::vector<RenderObject> renderObjects = std::vector<RenderObject>();
GLFWwindow* window;
glm::mat4 cameraTransform = glm::mat4(1.0f);
glm::mat4 projectionTransform = glm::mat4(1.0f);
2 years ago
};
class Obj2D : public RenderObject {
public:
using RenderObject::RenderObject;
2 years ago
void setTexture(const char* t_src);
void preRenderHook();
private:
Textures::Texture2D texture;
2 years ago
void bind_texture(Textures::Texture2D texture);
};
}