From 743e7d14caa91600532606c8e3361952e678bcad Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 20 Oct 2023 15:10:14 +0200 Subject: [PATCH] cli arg for base program --- src/graphics.cpp | 20 ++++++++++++++++++++ src/graphics.hpp | 1 + src/main.cpp | 32 ++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/graphics.cpp b/src/graphics.cpp index baeecd4..6d150a1 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -1,4 +1,6 @@ +#include #include +#include #include #include // glad must be loaded before GLFW @@ -9,6 +11,22 @@ using namespace std; +ShaderProgram::Base ShaderProgram::baseFromName(string name) { + string lname = name; + boost::algorithm::to_lower(lname); // yes, cpp needs a library to do this. + // can't do a switch over strings in cpp. + if (lname == "empty") { + return Empty; + } + if (lname == "triangle") { + return Triangle; + } + else { + BOOST_LOG_TRIVIAL(fatal) << "unknown base program \"" << name << "\""; + exit(EXIT_USAGE); + } +} + /* class ShaderProgram Implementations */ string ShaderProgram::baseName() { /* @@ -64,6 +82,8 @@ int ShaderProgram::run() { return 0; } +/* functions that run out graphics stuff */ + void framebuffer_size_callback(GLFWwindow *window, int width, int height) { glViewport(0, 0, width, height); } diff --git a/src/graphics.hpp b/src/graphics.hpp index 9dc1039..54c2376 100644 --- a/src/graphics.hpp +++ b/src/graphics.hpp @@ -9,6 +9,7 @@ class ShaderProgram { public: enum Base { Empty, Triangle }; std::string baseName(); + static Base baseFromName(std::string name); ShaderProgram(Base base, char** vertexSource, char** fragSource); int run(); diff --git a/src/main.cpp b/src/main.cpp index d2afa7e..85f1270 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,14 +15,15 @@ int main(int argc, char **argv) { po::options_description desc("Available options"); desc.add_options()("help,h", "show help")("verbose,v", "more verbose output")( "vert", po::value()->required(), "vertex shader file")( - "frag", po::value()->required(), "fragment shader file"); + "frag", po::value()->required(), "fragment shader file")( + "base,b", po::value()->required(), "base program"); /* unused for now */ po::positional_options_description pdesc; // NOTE: if you want to add a positional argument, // you need to create and option for it as it seems. - pdesc.add("vert", 1); - pdesc.add("frag", 1); + /* pdesc.add("vert", 1); */ + /* pdesc.add("frag", 1); */ po::variables_map vm; try { @@ -54,11 +55,14 @@ int main(int argc, char **argv) { } /* init graphics stuff */ - GLFWwindow* window = initGl(); + GLFWwindow *window = initGl(); if (result != 0) { return EXIT_GL; } + /* find the requested */ + ShaderProgram::Base base = ShaderProgram::baseFromName(vm["base"].as()); + /* setup the shader program */ BOOST_LOG_TRIVIAL(trace) << "Reading shader files"; auto fvert = fopen(vm["vert"].as().c_str(), "r"); @@ -79,9 +83,11 @@ int main(int argc, char **argv) { char *frag = (char *)malloc(sfrag + 1); fread(vert, sizeof(char), svert, fvert); fread(frag, sizeof(char), sfrag, ffrag); - BOOST_LOG_TRIVIAL(debug) << "vert file:\n```glsl\n" << vert << "```\n" + BOOST_LOG_TRIVIAL(debug) << "vert file:\n```glsl\n" + << vert << "```\n" << svert << "B"; - BOOST_LOG_TRIVIAL(debug) << "frag file:\n```glsl\n" << frag << "```\n" + BOOST_LOG_TRIVIAL(debug) << "frag file:\n```glsl\n" + << frag << "```\n" << sfrag << "B"; fclose(fvert); fclose(ffrag); @@ -89,7 +95,7 @@ int main(int argc, char **argv) { BOOST_LOG_TRIVIAL(trace) << "Creating ShaderProgram"; // TODO: determinde ShaderProgram::Base with a CLI arg - ShaderProgram shaderProgram(ShaderProgram::Base::Empty, &vert, &frag); + ShaderProgram shaderProgram(base, &vert, &frag); /* Run our main program */ BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow"; @@ -106,12 +112,18 @@ void help(char *prog, po::options_description desc) { << endl << endl << "return values:" << endl - << "0\tSuccess" - << "1\tGeneric Failure" - << "2\tBad arguments" + << "0\tSuccess" << endl + << "1\tGeneric Failure" << endl + << "2\tBad arguments" << endl << "3\tI/O Error" << endl << "3\tOpenGL Error" << endl << endl + << endl + << "base programs:" << endl + << "Empty\t\t-\tEmpty window with colored background" << endl + << "Triangle\t-\tA static Triangle" << endl + << endl + << endl << desc << endl; // NOTE: constants for the error codes are defined in main.hpp }