First ability to render slide text.

master
Zed A. Shaw 3 weeks ago
parent dc789b2d07
commit cb3786b508
  1. 49
      src/main.cpp
  2. 22
      src/render.cpp
  3. 16
      src/render.hpp

@ -8,9 +8,7 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "config.hpp" #include "config.hpp"
#include "render.hpp" #include "render.hpp"
#include "bezos.hpp"
float mouse_x = 0;
float mouse_y = 0;
void framebuffer_size_callback(GLFWwindow *window, int width, int height); 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) { void mouse_callback(GLFWwindow *window, double xpos, double ypos) {
fmt::println("mouse click: {},{}", xpos, ypos); Engine* engine = static_cast<Engine*>(glfwGetWindowUserPointer(window));
mouse_x = xpos; engine->mouse(xpos, ypos);
mouse_y = ypos; }
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
Engine* engine = static_cast<Engine*>(glfwGetWindowUserPointer(window));
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
} }
void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) { 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() { GLFWwindow* create_window() {
@ -51,26 +62,13 @@ GLFWwindow* create_window() {
dbc::check(good, "failed to load GLAD"); dbc::check(good, "failed to load GLAD");
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwSetCursorPosCallback(window, mouse_callback); glfwSetCursorPosCallback(window, mouse_callback);
glfwSetScrollCallback(window, scroll_callback); glfwSetKeyCallback(window, key_callback);
return window; 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() { void setup() {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND); glEnable(GL_BLEND);
@ -84,7 +82,6 @@ void setup() {
void update(GLFWwindow* window) { void update(GLFWwindow* window) {
glfwPollEvents(); glfwPollEvents();
process_input(window);
} }
void render(GLFWwindow* window, Engine &state) { void render(GLFWwindow* window, Engine &state) {
@ -102,9 +99,11 @@ int main() {
auto window = create_window(); auto window = create_window();
setup(); setup();
Engine state; Deck deck = Bezos::load("lua/builder_test.lua");
Engine state(deck);
// glfwSetWindowUserPointer(window, scene.get()); glfwSetWindowUserPointer(window, &state);
while(!glfwWindowShouldClose(window)) { while(!glfwWindowShouldClose(window)) {
update(window); update(window);

@ -1,7 +1,10 @@
#include "render.hpp" #include "render.hpp"
#include "config.hpp" #include "config.hpp"
#include <algorithm>
Engine::Engine() { Engine::Engine(Deck &deck) :
deck(deck)
{
text.load_font(); text.load_font();
screen.init(); screen.init();
framebuffer.init(); framebuffer.init();
@ -13,9 +16,24 @@ void Engine::render() {
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
text.render(text_content, 25.0f, SCR_HEIGHT - text.font_size - 20, 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)); glm::vec3(1.0f, 1.0f, 1.0f));
}
}
framebuffer.commit(); framebuffer.commit();
framebuffer.draw(screen); 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));
}

@ -2,14 +2,24 @@
#include "screen.hpp" #include "screen.hpp"
#include "framebuffer.hpp" #include "framebuffer.hpp"
#include "text.hpp" #include "text.hpp"
#include "document.hpp"
struct Engine { struct Engine {
Deck& deck;
FrameBuffer framebuffer; FrameBuffer framebuffer;
Screen screen; Screen screen;
std::string text_content{"Hi!"}; Text text{.font_size=100};
Text text{.font_size=202}; int at_slide = 0;
float mouse_x = 0.0f;
float mouse_y = 0.0f;
Engine(); Engine(Deck& deck);
void render(); void render();
void change_slide(int dir);
void mouse(float x, float y) {
mouse_x = x;
mouse_y = y;
}
}; };

Loading…
Cancel
Save