From cb3786b5085d6f19bc857356cee9b4bc05febefc Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 20 Oct 2026 15:36:16 -0400 Subject: [PATCH] First ability to render slide text. --- src/main.cpp | 49 ++++++++++++++++++++++++------------------------- src/render.cpp | 24 +++++++++++++++++++++--- src/render.hpp | 16 +++++++++++++--- 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1d8e0cf..8699913 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,9 +8,7 @@ #include #include "config.hpp" #include "render.hpp" - -float mouse_x = 0; -float mouse_y = 0; +#include "bezos.hpp" void framebuffer_size_callback(GLFWwindow *window, int width, int height); @@ -31,12 +29,25 @@ void framebuffer_size_callback(GLFWwindow *, int width, int height) { } void mouse_callback(GLFWwindow *window, double xpos, double ypos) { - fmt::println("mouse click: {},{}", xpos, ypos); - mouse_x = xpos; - mouse_y = ypos; + Engine* engine = static_cast(glfwGetWindowUserPointer(window)); + engine->mouse(xpos, ypos); } -void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) { +void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) +{ + Engine* engine = static_cast(glfwGetWindowUserPointer(window)); + + if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { + glfwSetWindowShouldClose(window, true); + } + + if (key == GLFW_KEY_W && action == GLFW_PRESS) { + engine->change_slide(-1); + } + + if (key == GLFW_KEY_S && action == GLFW_PRESS) { + engine->change_slide(1); + } } GLFWwindow* create_window() { @@ -51,26 +62,13 @@ GLFWwindow* create_window() { dbc::check(good, "failed to load GLAD"); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); + glfwSetCursorPosCallback(window, mouse_callback); - glfwSetScrollCallback(window, scroll_callback); + glfwSetKeyCallback(window, key_callback); return window; } -void process_input(GLFWwindow *window) { - if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { - glfwSetWindowShouldClose(window, true); - } - - if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { - fmt::println("move window left"); - } - - if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { - fmt::println("move window left"); - } -} - void setup() { glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); @@ -84,7 +82,6 @@ void setup() { void update(GLFWwindow* window) { glfwPollEvents(); - process_input(window); } void render(GLFWwindow* window, Engine &state) { @@ -102,9 +99,11 @@ int main() { auto window = create_window(); setup(); - Engine state; + Deck deck = Bezos::load("lua/builder_test.lua"); + + Engine state(deck); - // glfwSetWindowUserPointer(window, scene.get()); + glfwSetWindowUserPointer(window, &state); while(!glfwWindowShouldClose(window)) { update(window); diff --git a/src/render.cpp b/src/render.cpp index ec99ba6..5b1b315 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -1,7 +1,10 @@ #include "render.hpp" #include "config.hpp" +#include -Engine::Engine() { +Engine::Engine(Deck &deck) : + deck(deck) +{ text.load_font(); screen.init(); framebuffer.init(); @@ -13,9 +16,24 @@ void Engine::render() { 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)); + auto& slide = deck.slides.at(at_slide); + float line = 0; + + for(auto& node : slide.content) { + if(node.type == NodeType::TEXT || node.type == NodeType::H1 || node.type == NodeType::UL) { + line++; + float y = (text.font_size + 20) * line; + text.render(node.content, 25.0f, SCR_HEIGHT - y, 1.0f, + glm::vec3(1.0f, 1.0f, 1.0f)); + } + } framebuffer.commit(); framebuffer.draw(screen); } + +void Engine::change_slide(int dir) { + if(deck.slides.size() == 0) at_slide = 0; + + at_slide = std::clamp(at_slide + dir, 0, int(deck.slides.size() - 1)); +} diff --git a/src/render.hpp b/src/render.hpp index 7d95d16..cb38be3 100644 --- a/src/render.hpp +++ b/src/render.hpp @@ -2,14 +2,24 @@ #include "screen.hpp" #include "framebuffer.hpp" #include "text.hpp" +#include "document.hpp" struct Engine { + Deck& deck; FrameBuffer framebuffer; Screen screen; - std::string text_content{"Hi!"}; - Text text{.font_size=202}; + Text text{.font_size=100}; + int at_slide = 0; + float mouse_x = 0.0f; + float mouse_y = 0.0f; - Engine(); + Engine(Deck& deck); void render(); + void change_slide(int dir); + + void mouse(float x, float y) { + mouse_x = x; + mouse_y = y; + } };