Onyx-Engine/src/core/renderer/Renderer.h

74 lines
1.9 KiB
C
Raw Normal View History

2025-05-22 02:55:38 +00:00
// File: src/Renderer.h
#pragma once
2025-05-21 15:16:46 +00:00
#include "glm/glm.hpp"
2025-05-22 02:55:38 +00:00
#include "systems/Shader.h"
#include <gl/glew.h>
2025-05-21 15:16:46 +00:00
namespace OX {
2025-05-22 02:55:38 +00:00
struct Sprite {
GLuint textureID;
glm::vec2 position;
glm::vec2 size;
};
class Camera2D {
public:
Camera2D(float left, float right, float bottom, float top);
void SetPosition(const glm::vec2& pos);
void SetZoom(float zoom);
const glm::mat4& GetViewProjection() const;
private:
void Recalculate();
glm::vec2 _position{0.0f};
float _zoom{1.0f};
float _left, _right, _bottom, _top;
glm::mat4 _viewProj{1.0f};
};
class Renderer {
public:
Renderer() = default;
~Renderer();
/// Must call once after OpenGL context + GLEW init.
/// Provide the desired offscreen target size here.
void Init(int targetWidth, int targetHeight);
/// Call at start of each scene (binds FBO and sets camera).
void BeginScene(const Camera2D& camera);
/// Draw one sprite into the current scene.
void DrawSprite(const Sprite& sprite);
/// Finish rendering, unbinds FBO.
void EndScene();
/// Access the colorattachment texture ID that holds the rendered scene.
GLuint GetRenderTexture() const { return m_colorTex; }
/// If window resized, call this to resize the offscreen target.
void ResizeTarget(int width, int height);
private:
// offscreen
GLuint m_fbo = 0;
GLuint m_colorTex = 0;
GLuint m_depthRBO = 0;
2025-05-21 15:16:46 +00:00
2025-05-22 02:55:38 +00:00
// quad geometry
GLuint m_quadVAO = 0, m_quadVBO = 0;
2025-05-21 15:16:46 +00:00
2025-05-22 02:55:38 +00:00
// shader
Shader m_shader;
glm::mat4 m_viewProj{1.0f};
2025-05-21 15:16:46 +00:00
2025-05-22 02:55:38 +00:00
// helpers
void CreateQuad();
void CreateFramebuffer(int width, int height);
};
2025-05-21 15:16:46 +00:00
2025-05-22 02:55:38 +00:00
} // namespace OX