ThreeLab/Engine/Engine.h

63 lines
1.9 KiB
C
Raw Normal View History

2025-04-01 16:45:59 +00:00
#ifndef ENGINE_H
#define ENGINE_H
2025-04-01 16:02:52 +00:00
#include <iostream>
2025-04-01 20:03:18 +00:00
#include <vector>
2025-04-01 16:45:59 +00:00
#include <GL/glew.h>
2025-04-01 01:25:39 +00:00
#include <GLFW/glfw3.h>
2025-04-01 16:45:59 +00:00
#include "imgui.h"
#include "imgui_impl_opengl3.h"
#include "imgui_impl_glfw.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
2025-04-01 01:25:39 +00:00
2025-04-01 16:53:23 +00:00
#include "Components/Component.h"
#include "Components/Camera.h"
2025-04-01 20:03:18 +00:00
// Forward declaration of Entity.
class Entity;
2025-04-01 16:53:23 +00:00
2025-04-01 16:45:59 +00:00
class Engine {
public:
// Main window.
static GLFWwindow* window;
2025-04-01 16:02:52 +00:00
2025-04-01 16:45:59 +00:00
// Initializes GLFW, GLEW, and sets up the main window and offscreen framebuffer.
static bool Init();
// Returns the main GLFW window.
static GLFWwindow* GetWindow();
// Clean up resources and shutdown GLFW.
static void Shutdown();
2025-04-01 16:02:52 +00:00
2025-04-01 20:19:00 +00:00
// Offscreen render function that uses the provided camera parameters and renders the scene
// (with entities) offscreen. Returns its color attachment as an ImTextureID.
2025-04-01 20:03:18 +00:00
static ImTextureID RenderScene(const glm::mat4 &view, const glm::mat4 &projection, const glm::vec3 &viewPos, const std::vector<Entity*>& entities);
2025-04-01 16:02:52 +00:00
2025-04-01 16:45:59 +00:00
// Resizes the offscreen framebuffer to the given dimensions.
static void ResizeFramebuffer(int width, int height);
2025-04-01 16:02:52 +00:00
2025-04-01 16:45:59 +00:00
// Retrieves the final rendered texture.
static ImTextureID GetFinalRenderingTexture();
2025-04-01 16:02:52 +00:00
2025-04-01 16:45:59 +00:00
private:
// Offscreen framebuffer and its attachments.
static GLuint framebuffer;
static GLuint colorTexture;
static GLuint depthRenderbuffer;
// Shader program used for rendering the scene.
static GLuint shaderProgram;
2025-04-01 20:19:00 +00:00
// Rotation angle (if needed for animated models).
2025-04-01 16:45:59 +00:00
static float rotationAngle;
// Current offscreen framebuffer dimensions.
static int fbWidth;
static int fbHeight;
// Helper function to compile and link shaders.
static GLuint CompileShader(const char* vertexSrc, const char* fragmentSrc);
2025-04-01 20:19:00 +00:00
// Sets up common scene resources (e.g. loading the scene shader).
2025-04-01 16:45:59 +00:00
static bool SetupScene();
2025-04-01 01:25:39 +00:00
};
2025-04-01 16:45:59 +00:00
#endif // ENGINE_H