mirror of
https://github.com/guezoloic/LearnOpenGL.git
synced 2026-01-25 07:34:16 +00:00
feat!: rework header files
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
#ifndef CAMERA_HPP
|
#ifndef CAMERA_HPP
|
||||||
#define CAMERA_HPP
|
#define CAMERA_HPP
|
||||||
|
|
||||||
#include "glm/ext/vector_float3.hpp"
|
#include "GLFW/glfw3.h"
|
||||||
#include "glm/ext/matrix_float4x4.hpp"
|
#include "glm/ext/matrix_float4x4.hpp"
|
||||||
|
#include "glm/ext/vector_float3.hpp"
|
||||||
struct GLFWwindow;
|
|
||||||
|
|
||||||
class Camera
|
class Camera
|
||||||
{
|
{
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
class EBO
|
class EBO
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -19,4 +20,5 @@ class EBO
|
|||||||
void bind();
|
void bind();
|
||||||
void unbind();
|
void unbind();
|
||||||
};
|
};
|
||||||
#endif
|
}; // namespace core
|
||||||
|
#endif // EBO_HPP
|
||||||
53
inc/core/logger.hpp
Normal file
53
inc/core/logger.hpp
Normal 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
|
||||||
30
inc/core/time.hpp
Normal file
30
inc/core/time.hpp
Normal 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
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
#ifndef CUBE_HPP
|
#ifndef CUBE_HPP
|
||||||
#define CUBE_HPP
|
#define CUBE_HPP
|
||||||
|
|
||||||
#include "camera.hpp"
|
|
||||||
#include "glm/ext/vector_float3.hpp"
|
#include "glm/ext/vector_float3.hpp"
|
||||||
#include "shape.hpp"
|
#include "shape.hpp"
|
||||||
|
|
||||||
class Cube : public Shape
|
class Cube : public Shape
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Cube(Camera &camera, glm::vec3 pos, std::string texture);
|
Cube(Camera &camera, glm::vec3 pos, const char *texture);
|
||||||
void render(int width, int height) override;
|
void render(int width, int height) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
26
inc/game.hpp
Normal file
26
inc/game.hpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef GAME_HPP
|
||||||
|
#define GAME_HPP
|
||||||
|
|
||||||
|
#include "GLFW/glfw3.h"
|
||||||
|
#include "core/time.hpp"
|
||||||
|
|
||||||
|
// class Game
|
||||||
|
// {
|
||||||
|
// private:
|
||||||
|
// Time time;
|
||||||
|
// GLFWwindow *window = nullptr;
|
||||||
|
// const char *WINDOW_NAME;
|
||||||
|
// int width;
|
||||||
|
// int height;
|
||||||
|
|
||||||
|
// int init();
|
||||||
|
|
||||||
|
// protected:
|
||||||
|
// public:
|
||||||
|
// Game(int width, int height, const char *window_name);
|
||||||
|
// void run();
|
||||||
|
|
||||||
|
// static void error(const char *type, int errortype, const char *desc);
|
||||||
|
// };
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
#include "GLFW/glfw3.h"
|
|
||||||
|
|
||||||
constexpr GLfloat P_CUBE_VERTICE[] = {
|
|
||||||
// Positions // normales // texture coordinate
|
|
||||||
// front side
|
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
|
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
|
|
||||||
// back side
|
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
|
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
|
||||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
|
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
|
||||||
|
|
||||||
// left side
|
|
||||||
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
|
||||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
|
|
||||||
// right side
|
|
||||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
|
||||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
|
|
||||||
// bottom side
|
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
|
|
||||||
// up side
|
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr unsigned int P_CUBE_INDICE[] = {
|
|
||||||
0, 1, 2, // 1
|
|
||||||
2, 3, 0, // 2
|
|
||||||
|
|
||||||
4, 5, 6, // 3
|
|
||||||
6, 7, 4, // 4
|
|
||||||
|
|
||||||
8, 9, 10, // 5
|
|
||||||
10, 11, 8, // 6
|
|
||||||
|
|
||||||
12, 13, 14, // 7
|
|
||||||
14, 15, 12, // 8
|
|
||||||
|
|
||||||
16, 17, 18, // 9
|
|
||||||
18, 19, 16, // 10
|
|
||||||
|
|
||||||
20, 21, 22, // 11
|
|
||||||
22, 23, 20 // 12
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" const unsigned char P_CUBE_FRAG[];
|
|
||||||
extern "C" const unsigned int P_CUBE_FRAG_LEN;
|
|
||||||
extern "C" const unsigned char P_CUBE_VERT[];
|
|
||||||
extern "C" const unsigned int P_CUBE_VERT_LEN;
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#ifndef SHAPE_HPP
|
#ifndef SHAPE_HPP
|
||||||
#define SHAPE_HPP
|
#define SHAPE_HPP
|
||||||
|
|
||||||
#include "camera.hpp"
|
#include "core/camera.hpp"
|
||||||
#include "ebo.hpp"
|
#include "core/ebo.hpp"
|
||||||
|
#include "core/shader.hpp"
|
||||||
|
#include "core/texture.hpp"
|
||||||
|
#include "core/vao.hpp"
|
||||||
|
#include "core/vbo.hpp"
|
||||||
#include "glm/ext/vector_float3.hpp"
|
#include "glm/ext/vector_float3.hpp"
|
||||||
#include "shader.hpp"
|
|
||||||
#include "texture.hpp"
|
|
||||||
#include "vao.hpp"
|
|
||||||
#include "vbo.hpp"
|
|
||||||
|
|
||||||
class Shape
|
class Shape
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user