feat!: rework header files

This commit is contained in:
2026-01-06 20:07:44 +01:00
parent f4f9f4a7ac
commit 66761b8e5d
12 changed files with 122 additions and 78 deletions

67
inc/core/camera.hpp Executable file
View File

@@ -0,0 +1,67 @@
#ifndef CAMERA_HPP
#define CAMERA_HPP
#include "GLFW/glfw3.h"
#include "glm/ext/matrix_float4x4.hpp"
#include "glm/ext/vector_float3.hpp"
class Camera
{
private:
int width;
int height;
double mousePosX;
double mousePosY;
// first mouse detection
bool firstMouse = true;
float cameraYaw = -90.f; // horizontal angle
float cameraPitch = 10.f; // vertical angle
// front camera vector (where the camera is pointed.)
glm::vec3 cameraFront = glm::vec3(0.f, 0.f, -1.f);
// up world vector (absolute up pos)
glm::vec3 worldUp = glm::vec3(0.f, 1.f, 0.f);
// up camera vector (relative up from the camera)
glm::vec3 cameraUp;
// right camera vector (relative right from the camera)
glm::vec3 cameraRight;
// camera position
glm::vec3 cameraPosition = glm::vec3(0.f, 0.f, 0.f);
// glfw window
GLFWwindow* window;
float speed = 3.f; // move speed
float cameraSensitivity; // mouse sensitivity
float fov = 45.f; // Field Of View
void processInput(float deltaTime);
void processMouseMovement();
void updateCameraVectors();
public:
Camera(int width, int height, GLFWwindow* window, float sensitivity);
void update(float deltaTime);
// view matrix
glm::mat4 getViewMatrix() const;
// projection matrix
glm::mat4 getProjectionMatrix() const;
float getFov() const { return fov; }
float getSpeed() const { return speed; }
float getCameraSensitivity() const { return cameraSensitivity; }
glm::vec3 getPosition() const { return cameraPosition; }
void setSpeed(float newSpeed);
void setCameraSensitivity(float newSensitivity);
void setFov(float newFov);
void setPosition(const glm::vec3& newPosition);
};
#endif

24
inc/core/ebo.hpp Executable file
View File

@@ -0,0 +1,24 @@
#ifndef EBO_HPP
#define EBO_HPP
#include <stddef.h>
#include "glad/glad.h"
namespace core
{
class EBO
{
private:
GLuint id;
public:
EBO();
~EBO();
void setData(const unsigned int* indices, size_t size);
void bind();
void unbind();
};
}; // namespace core
#endif // EBO_HPP

53
inc/core/logger.hpp Normal file
View File

@@ -0,0 +1,53 @@
#ifndef LOGGER_HPP
#define LOGGER_HPP
#include <iostream>
// log file
namespace core::log
{
enum Type
{
INFO,
ERROR,
WARNING
};
static inline const char *getErrorType(Type type)
{
switch (type)
{
case INFO:
return "INFO";
case ERROR:
return "ERROR";
case WARNING:
return "WARNING";
}
return "UNKNOWN";
}
inline void log(Type type, const char *desc, int errortype = 0)
{
std::cerr << getErrorType(type) << " ERROR"
<< ((errortype) ? std::format("({})", errortype) : "") << ": "
<< desc << std::endl;
}
inline void info(const char *desc, int codeerror = 0)
{
log(Type::INFO, desc, codeerror);
}
inline void error(const char *desc, int codeerror = 0)
{
log(Type::ERROR, desc, codeerror);
}
inline void warning(const char *desc, int codeerror = 0)
{
log(Type::WARNING, desc, codeerror);
}
}; // namespace core::log
#endif // LOGGER_HPP

35
inc/core/shader.hpp Executable file
View File

@@ -0,0 +1,35 @@
#ifndef SHADER_HPP
#define SHADER_HPP
#include "glad/glad.h"
class Shader
{
private:
GLuint vertexShaderID; // vertex shader id
GLuint fragmentShaderID; // fragment shader id
// final compiled shader program id used by the gpu
GLuint shaderProgramID;
// compile vertex shader source code
void addVertShader(const char* vertexSource);
// compile fragment shader source code
void addFragShader(const char* fragmentSource);
// link both compile vertex and fragment shader
void compileInProgram();
public:
// Does nothing apart initializing all IDs to 0
Shader();
// compile and link vertex and fragment into the shader struct
void compile(const char* vertexSource, const char* fragmentSource);
// free shader program
~Shader();
GLuint getShaderProgramID() const;
// activate shader program into gpu pipeline
void use() const;
};
#endif

20
inc/core/texture.hpp Executable file
View File

@@ -0,0 +1,20 @@
#ifndef TEXTUTE_HPP
#define TEXTUTE_HPP
#include "glad/glad.h"
#include <string>
class Texture
{
private:
unsigned int id;
public:
Texture(const std::string& path);
~Texture();
void bind(GLenum textureUnit) const;
unsigned int getID() const;
};
#endif

30
inc/core/time.hpp Normal file
View File

@@ -0,0 +1,30 @@
#ifndef TIME_HPP
#define TIME_HPP
#include "GLFW/glfw3.h"
class Time
{
private:
double deltaTime = 0.;
double lastDTime = 0.;
public:
double getDeltaTime() const { return deltaTime; }
double getLastDeltaTime() const { return lastDTime; }
void start()
{
deltaTime = glfwGetTime();
lastDTime = 0.;
}
void update()
{
double currentTime = glfwGetTime();
deltaTime = currentTime - lastDTime;
lastDTime = currentTime;
}
};
#endif

27
inc/core/vao.hpp Executable file
View File

@@ -0,0 +1,27 @@
#ifndef VAO_HPP
#define VAO_HPP
#include <stddef.h>
#include "glad/glad.h"
class VAO
{
private:
unsigned int id;
public:
VAO();
~VAO();
void bind();
void unbind();
void setAttributePointer(GLuint index, GLuint size, GLenum type,
GLsizei stride, const void* offset);
void drawElement(GLenum mode, GLsizei count, GLenum type,
const void* indices);
void drawArray(GLenum mode, GLint first, GLsizei count);
};
#endif

23
inc/core/vbo.hpp Executable file
View File

@@ -0,0 +1,23 @@
#ifndef VBO_HPP
#define VBO_HPP
#include <stddef.h>
#include "glad/glad.h"
class VBO
{
private:
unsigned int id;
public:
VBO();
~VBO();
void setData(const GLfloat* vertices, size_t size);
void bind();
void unbind();
};
#endif