diff --git a/meson.build b/meson.build index e0057c2..dddbce6 100644 --- a/meson.build +++ b/meson.build @@ -39,6 +39,7 @@ sources = [ 'src/document.cpp', 'src/framebuffer.cpp', 'src/screen.cpp', + 'src/render.cpp', ] tests = [ diff --git a/src/main.cpp b/src/main.cpp index f06da80..1d8e0cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,28 +6,14 @@ #include #include #include -#include "text.hpp" #include "config.hpp" -#include "screen.hpp" -#include "framebuffer.hpp" +#include "render.hpp" float mouse_x = 0; float mouse_y = 0; void framebuffer_size_callback(GLFWwindow *window, int width, int height); -struct State { - FrameBuffer framebuffer; - Screen screen; - std::string text_content{"Hi!"}; - Text text{.font_size=202}; - - State() { - text.load_font(); - screen.init(); - framebuffer.init(); - } -}; void init_glfw() { glfwInit(); @@ -101,17 +87,8 @@ void update(GLFWwindow* window) { process_input(window); } -void render(GLFWwindow* window, State &state) { - state.framebuffer.begin(); - - glClearColor(0.1f, 0.1f, 0.1f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - - state.text.render(state.text_content, 25.0f, SCR_HEIGHT - state.text.font_size - 20, 1.0f, - glm::vec3(1.0f, 1.0f, 1.0f)); - - state.framebuffer.commit(); - state.framebuffer.draw(state.screen); +void render(GLFWwindow* window, Engine &state) { + state.render(); glfwSwapBuffers(window); } @@ -125,7 +102,7 @@ int main() { auto window = create_window(); setup(); - State state; + Engine state; // glfwSetWindowUserPointer(window, scene.get()); diff --git a/src/render.cpp b/src/render.cpp new file mode 100644 index 0000000..ec99ba6 --- /dev/null +++ b/src/render.cpp @@ -0,0 +1,21 @@ +#include "render.hpp" +#include "config.hpp" + +Engine::Engine() { + text.load_font(); + screen.init(); + framebuffer.init(); +} + +void Engine::render() { + framebuffer.begin(); + + glClearColor(0.1f, 0.1f, 0.1f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + text.render(text_content, 25.0f, SCR_HEIGHT - text.font_size - 20, 1.0f, + glm::vec3(1.0f, 1.0f, 1.0f)); + + framebuffer.commit(); + framebuffer.draw(screen); +} diff --git a/src/render.hpp b/src/render.hpp new file mode 100644 index 0000000..7d95d16 --- /dev/null +++ b/src/render.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "screen.hpp" +#include "framebuffer.hpp" +#include "text.hpp" + +struct Engine { + FrameBuffer framebuffer; + Screen screen; + std::string text_content{"Hi!"}; + Text text{.font_size=202}; + + Engine(); + + void render(); +};