modules are good now
This commit is contained in:
parent
f0cb371955
commit
001d795b73
1
build.sh
1
build.sh
|
@ -5,4 +5,5 @@ cmake $flags .
|
||||||
cmake --build .
|
cmake --build .
|
||||||
echo -e "running the program, passing the given args"
|
echo -e "running the program, passing the given args"
|
||||||
echo -e "========================================"
|
echo -e "========================================"
|
||||||
|
# shellcheck disable=SC2046 # Intended splitting of OPTIONS
|
||||||
./run.sh $@
|
./run.sh $@
|
||||||
|
|
1
run.sh
1
run.sh
|
@ -1,3 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
# shellcheck disable=SC2046 # Intended splitting of OPTIONS
|
||||||
./bin/loader/loader $@
|
./bin/loader/loader $@
|
||||||
|
|
|
@ -1,28 +1,33 @@
|
||||||
|
#include <glad/glad.c>
|
||||||
|
// glad must be loaded before GLFW
|
||||||
#include "graphics.hpp"
|
#include "graphics.hpp"
|
||||||
|
#include "main.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/* class ShaderProgram Implementations */
|
||||||
string ShaderProgram::baseName() {
|
string ShaderProgram::baseName() {
|
||||||
switch (this->base) {
|
switch (this->base) {
|
||||||
case Empty:
|
case Empty:
|
||||||
return "Empty";
|
return "Empty";
|
||||||
case Triangle:
|
case Triangle:
|
||||||
return "Triangle";
|
return "Triangle";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mainWindow(ShaderProgram shaderProgram) {
|
/* extended main function */
|
||||||
|
int mainWindow(ShaderProgram* shaderProgram) {
|
||||||
/* graphics stuff */
|
/* graphics stuff */
|
||||||
glfwInit();
|
glfwInit();
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
|
@ -45,7 +50,7 @@ int mainWindow(ShaderProgram shaderProgram) {
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
int result = shaderProgram.run();
|
int result = shaderProgram->run();
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#ifndef GRAPHICS_HPP
|
#ifndef GRAPHICS_HPP
|
||||||
#define GRAPHICS_HPP
|
#define GRAPHICS_HPP
|
||||||
#include <glad/glad.c>
|
|
||||||
// glad must be loaded before GLFW
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -11,7 +9,7 @@ class ShaderProgram {
|
||||||
public:
|
public:
|
||||||
enum Base { Empty, Triangle };
|
enum Base { Empty, Triangle };
|
||||||
std::string baseName();
|
std::string baseName();
|
||||||
ShaderProgram(Base base, std::string vertexFile, std::string fragFile);
|
ShaderProgram(Base base, std::string vertexSource, std::string fragSource);
|
||||||
int run();
|
int run();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
64
src/main.cpp
64
src/main.cpp
|
@ -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 <iostream>
|
||||||
|
|
||||||
#include "graphics.hpp"
|
#include "main.hpp"
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int main(int argc, char **argv);
|
|
||||||
|
|
||||||
void help(char *prog, po::options_description desc);
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
@ -45,19 +35,45 @@ int main(int argc, char **argv) {
|
||||||
} catch (po::error &e) {
|
} catch (po::error &e) {
|
||||||
cout << e.what() << endl << endl;
|
cout << e.what() << endl << endl;
|
||||||
help(argv[0], desc);
|
help(argv[0], desc);
|
||||||
return 1;
|
return EXIT_USAGE;
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.count("verbose")) {
|
|
||||||
printf("verbose!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup the shader program */
|
/* setup the shader program */
|
||||||
ShaderProgram* shaderProgram = new ShaderProgram(
|
if (vm.count("verbose")) {
|
||||||
ShaderProgram::Base::Empty, vm["vert"].as<string>(), vm["frag"].as<string>());
|
// 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 */
|
/* Run our main program */
|
||||||
int result = mainWindow(shaderProgram);
|
if (vm.count("verbose")) {
|
||||||
|
printf("Starting mainWindow\n");
|
||||||
|
}
|
||||||
|
int result = mainWindow(&shaderProgram);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -68,5 +84,13 @@ void help(char *prog, po::options_description desc) {
|
||||||
<< " [-vh] [--vert] shaders/vertex.glsl [--frag] shaders/fragment.glsl"
|
<< " [-vh] [--vert] shaders/vertex.glsl [--frag] shaders/fragment.glsl"
|
||||||
<< endl
|
<< endl
|
||||||
<< 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;
|
<< desc << endl;
|
||||||
|
// NOTE: constants for the error codes are defined in main.hpp
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue