diff --git a/Makefile b/Makefile index 5bfefd0..adcab3a 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +SAMPLE=lua/builder_test.lua + all: test reset: @@ -24,9 +26,9 @@ test: build run: build test ifeq '$(OS)' 'Windows_NT' powershell "cp ./builddir/bezos.exe ." - ./bezos + ./bezos -d $(SAMPLE) else - ./builddir/bezos + ./builddir/bezos -d $(SAMPLE) endif debug: build diff --git a/meson.build b/meson.build index da83fdb..7b973ba 100644 --- a/meson.build +++ b/meson.build @@ -41,6 +41,7 @@ sources = [ 'src/screen.cpp', 'src/engine.cpp', 'src/image.cpp', + 'src/options.cpp', ] tests = [ diff --git a/src/config.hpp b/src/config.hpp index 4c41785..a1fde1c 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -1,6 +1,8 @@ #pragma once -#define INSTANCE_COUNT 5 - -const unsigned int SCR_WIDTH = 1792; -const unsigned int SCR_HEIGHT = 1008; +constexpr const int WINDOW_WIDTH=1280; +constexpr const int WINDOW_HEIGHT=720; +constexpr const int FRAME_LIMIT=60; +constexpr const bool VSYNC=true; +constexpr const int CONTROL_WIDTH=1000; +constexpr const int CONTROL_HEIGHT=1000; diff --git a/src/engine.cpp b/src/engine.cpp index 8af8472..4608442 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -47,7 +47,7 @@ void init_glfw() { GLFWwindow* create_window() { - GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "LearnOpenGL", NULL, NULL); dbc::check(window != NULL, "failed to open window"); glfwMakeContextCurrent(window); @@ -109,7 +109,7 @@ void Engine::render() { float y = (text->font_size + 20) * line; if(node.type == NodeType::TEXT || node.type == NodeType::H1 || node.type == NodeType::UL) { - text->render(node.content, 25.0f, SCR_HEIGHT - y, 1.0f, glm::vec3(1.0f, 1.0f, 1.0f)); + text->render(node.content, 25.0f, WINDOW_HEIGHT - y, 1.0f, glm::vec3(1.0f, 1.0f, 1.0f)); } else if(node.type == NodeType::IMAGE && node.image != nullptr) { dbc::check(node.image != nullptr, "Node's image not configured."); node.image->render(); diff --git a/src/framebuffer.cpp b/src/framebuffer.cpp index c0917d0..cf9363b 100644 --- a/src/framebuffer.cpp +++ b/src/framebuffer.cpp @@ -9,7 +9,7 @@ void FrameBuffer::init() { glGenTextures(1, &texture_color_buffer); glBindTexture(GL_TEXTURE_2D, texture_color_buffer); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SCR_WIDTH, SCR_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WINDOW_WIDTH, WINDOW_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -17,7 +17,7 @@ void FrameBuffer::init() { glGenRenderbuffers(1, &target_rbo); glBindRenderbuffer(GL_RENDERBUFFER, target_rbo); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, SCR_WIDTH, SCR_HEIGHT); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, WINDOW_WIDTH, WINDOW_HEIGHT); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, target_rbo); dbc::check(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, "Failed to init framebuffer."); diff --git a/src/main.cpp b/src/main.cpp index f9a0953..9b3f9ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,9 +3,14 @@ #include "config.hpp" #include "engine.hpp" #include "bezos.hpp" +#include "options.hpp" -int main() { - Deck deck = Bezos::load("lua/builder_test.lua"); +int main(int argc, char* argv[]) { + Options opts = parse_options(argc, argv); + + if(opts.error) return 1; + + Deck deck = Bezos::load(opts.deck_file); Engine engine{.deck=deck}; engine.init(); diff --git a/src/options.cpp b/src/options.cpp new file mode 100644 index 0000000..9ba3b26 --- /dev/null +++ b/src/options.cpp @@ -0,0 +1,50 @@ +#include "options.hpp" +#include +#include + +void print_usage() { + fmt::println("USAGE: bezos [-W width] [-H height] [-p PORT] [-h] [-F] [-C] -d deck.md"); +} + +Options parse_options(int argc, char* argv[]) { + int opt = 0; + Options result; + + while((opt = getopt(argc, argv, "hpFCd:W:H:")) != -1) { + switch(opt) { + case 'h': + print_usage(); + return {.help=true}; + break; + case 'p': + result.port = std::stoi(optarg); + break; + case 'd': + result.deck_given=true; + result.deck_file = optarg; + break; + case 'W': + result.pres_size.x = std::stoi(optarg); + break; + case 'H': + result.pres_size.y = std::stoi(optarg); + break; + case 'F': + result.full_screen = true; + break; + case 'C': + result.control_window = false; + break; + default: + print_usage(); + return {.error=true}; + } + } + + if(!result.deck_given) { + print_usage(); + result.error = true; + } + + return result; +} diff --git a/src/options.hpp b/src/options.hpp new file mode 100644 index 0000000..b4ef16e --- /dev/null +++ b/src/options.hpp @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include "config.hpp" + +struct Options { + std::string deck_file{}; + bool deck_given{false}; + bool help{false}; + glm::vec2 pres_size{WINDOW_WIDTH, WINDOW_HEIGHT}; + glm::vec2 control_size{CONTROL_WIDTH, CONTROL_HEIGHT}; + bool error{false}; + unsigned short port=9898; + bool full_screen = false; + bool control_window = true; +}; + +void print_usage(); +Options parse_options(int argc, char* argv[]); diff --git a/src/text.cpp b/src/text.cpp index 9c6c748..ef1f6ed 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -10,7 +10,7 @@ void Text::render(const std::string& text, float x, float y, float scale, glm::vec3 color) { text_shader.use(); - glm::mat4 projection = glm::ortho(0.0f, static_cast(SCR_WIDTH), 0.0f, static_cast(SCR_HEIGHT)); + glm::mat4 projection = glm::ortho(0.0f, static_cast(WINDOW_WIDTH), 0.0f, static_cast(WINDOW_HEIGHT)); text_shader.setMat4("projection", projection); glUniform3f(glGetUniformLocation(text_shader.ID, "textColor"), color.x, color.y, color.z);