modules are good now

This commit is contained in:
Christoph J. Scherr 2023-10-18 19:48:48 +02:00
parent f0cb371955
commit 001d795b73
6 changed files with 82 additions and 32 deletions

View File

@ -5,4 +5,5 @@ cmake $flags .
cmake --build .
echo -e "running the program, passing the given args"
echo -e "========================================"
# shellcheck disable=SC2046 # Intended splitting of OPTIONS
./run.sh $@

1
run.sh
View File

@ -1,3 +1,4 @@
#!/bin/bash
set -e
# shellcheck disable=SC2046 # Intended splitting of OPTIONS
./bin/loader/loader $@

View File

@ -1,10 +1,13 @@
#include <glad/glad.c>
// glad must be loaded before GLFW
#include "graphics.hpp"
#include "main.hpp"
#include <iostream>
#include <fstream>
using namespace std;
/* class ShaderProgram Implementations */
string ShaderProgram::baseName() {
switch (this->base) {
case Empty:
@ -14,15 +17,17 @@ string ShaderProgram::baseName() {
}
}
ShaderProgram::ShaderProgram(Base base, string vertexFile, string fragFile) {
ShaderProgram::ShaderProgram(Base base, string vertexSource,
string fragSource) {}
}
int ShaderProgram::run() { return 255; }
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
glViewport(0, 0, width, height);
}
int mainWindow(ShaderProgram shaderProgram) {
/* extended main function */
int mainWindow(ShaderProgram* shaderProgram) {
/* graphics stuff */
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
@ -45,7 +50,7 @@ int mainWindow(ShaderProgram shaderProgram) {
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
int result = shaderProgram.run();
int result = shaderProgram->run();
glfwTerminate();
return result;

View File

@ -1,7 +1,5 @@
#ifndef GRAPHICS_HPP
#define GRAPHICS_HPP
#include <glad/glad.c>
// glad must be loaded before GLFW
#include <GLFW/glfw3.h>
#include <iostream>
@ -11,7 +9,7 @@ class ShaderProgram {
public:
enum Base { Empty, Triangle };
std::string baseName();
ShaderProgram(Base base, std::string vertexFile, std::string fragFile);
ShaderProgram(Base base, std::string vertexSource, std::string fragSource);
int run();
protected:

View File

@ -1,18 +1,8 @@
#include <boost/program_options.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/positional_options.hpp>
#include <boost/program_options/variables_map.hpp>
#include <fstream>
#include <iostream>
#include "graphics.hpp"
namespace po = boost::program_options;
using namespace std;
int main(int argc, char **argv);
void help(char *prog, po::options_description desc);
#include "main.hpp"
int main(int argc, char **argv) {
@ -45,19 +35,45 @@ int main(int argc, char **argv) {
} catch (po::error &e) {
cout << e.what() << endl << endl;
help(argv[0], desc);
return 1;
}
if (vm.count("verbose")) {
printf("verbose!");
return EXIT_USAGE;
}
/* setup the shader program */
ShaderProgram* shaderProgram = new ShaderProgram(
ShaderProgram::Base::Empty, vm["vert"].as<string>(), vm["frag"].as<string>());
if (vm.count("verbose")) {
// TODO: make verbose flag somehow global?
printf("Reading shader files\n");
}
ifstream vertexFileStream(vm["vert"].as<string>());
ifstream fragFileStream(vm["frag"].as<string>());
std::stringstream vertexSource;
std::stringstream fragSource;
vertexSource << vertexFileStream.rdbuf();
fragSource << fragFileStream.rdbuf();
if (vertexFileStream.fail()) {
cout << "Error while reading the vertex shader file." << endl;
return EXIT_IO;
}
if (fragFileStream.fail()) {
cout << "Error while reading the frag shader file." << endl;
return EXIT_IO;
}
vertexFileStream.close();
fragFileStream.close();
if (vm.count("verbose")) {
printf("Creating ShaderProgram\n");
}
// TODO: determinde ShaderProgram::Base with a CLI arg
ShaderProgram shaderProgram(ShaderProgram::Base::Empty, vertexSource.str(),
fragSource.str());
/* Run our main program */
int result = mainWindow(shaderProgram);
if (vm.count("verbose")) {
printf("Starting mainWindow\n");
}
int result = mainWindow(&shaderProgram);
return result;
}
@ -68,5 +84,13 @@ void help(char *prog, po::options_description desc) {
<< " [-vh] [--vert] shaders/vertex.glsl [--frag] shaders/fragment.glsl"
<< endl
<< endl
<< "return values:" << endl
<< "0\tSuccess"
<< "1\tGeneric Failure"
<< "2\tBad arguments"
<< "3\tI/O Error" << endl
<< "3\tOpenGL Error" << endl
<< endl
<< desc << endl;
// NOTE: constants for the error codes are defined in main.hpp
}

21
src/main.hpp Normal file
View File

@ -0,0 +1,21 @@
#ifndef MAIN_HPP
#define MAIN_HPP
#include <boost/program_options.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/positional_options.hpp>
#include <boost/program_options/variables_map.hpp>
#include "graphics.hpp"
// EXIT_FAILURE and EXIT_SUCCESS are defined in cstdlib
const int EXIT_USAGE = 2;
const int EXIT_IO = 3;
const int EXIT_GL = 4;
namespace po = boost::program_options;
using namespace std;
int main(int argc, char **argv);
void help(char *prog, po::options_description desc);
#endif