Compare commits

..

2 commits

Author SHA1 Message Date
613a917d36 boost logger 2023-10-18 20:02:46 +02:00
001d795b73 modules are good now 2023-10-18 19:56:44 +02:00
5 changed files with 28 additions and 11 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@ CMakeDoxygenDefaults.cmake
Makefile
cmake_install.cmake
bin/loader/loader
lib/glfw

View file

@ -30,7 +30,7 @@ source_group("sources" FILES ${PROJECT_SOURCES})
source_group("vendors" FILES ${VENDORS_SOURCES})
find_package(Boost 1.56 REQUIRED COMPONENTS
program_options)
program_options log)
set(EXE_1_NAME loader)
file(
@ -41,7 +41,7 @@ set(CMAKE_BINARY_DIR "bin")
add_executable(${EXE_1_NAME} ${EXE_1_SOURCES} ${PROJECT_HEADERS}
${PROJECT_SHADERS} ${VENDORS_SOURCES})
target_link_libraries(${EXE_1_NAME} glfw Boost::program_options)
target_link_libraries(${EXE_1_NAME} glfw Boost::program_options Boost::log)
target_include_directories(${EXE_1_NAME} PRIVATE include)
set_target_properties(${EXE_1_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${EXE_1_NAME})

View file

@ -1,11 +1,13 @@
#include <glad/glad.c>
// glad must be loaded before GLFW
#include "graphics.hpp"
#include "main.hpp"
#include <iostream>
using namespace std;
/* class ShaderProgram Implementations */
string ShaderProgram::baseName() {
switch (this->base) {
case Empty:
@ -24,6 +26,7 @@ void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
glViewport(0, 0, width, height);
}
/* extended main function */
int mainWindow(ShaderProgram* shaderProgram) {
/* graphics stuff */
glfwInit();

View file

@ -1,4 +1,3 @@
#include <fstream>
#include <iostream>
@ -33,16 +32,16 @@ int main(int argc, char **argv) {
return 1;
}
} catch (po::error &e) {
cout << e.what() << endl << endl;
BOOST_LOG_TRIVIAL(fatal) << e.what() << endl << endl;
help(argv[0], desc);
return EXIT_USAGE;
}
if (vm.count("verbose")) {
printf("verbose!");
}
/* setup the shader program */
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;
@ -51,20 +50,28 @@ int main(int argc, char **argv) {
fragSource << fragFileStream.rdbuf();
if (vertexFileStream.fail()) {
cout << "Error while reading the vertex shader file." << endl;
BOOST_LOG_TRIVIAL(fatal) << "Error while reading the vertex shader file." << endl;
return EXIT_IO;
}
if (fragFileStream.fail()) {
cout << "Error while reading the frag shader file." << endl;
if (!fragFileStream.fail()) {
BOOST_LOG_TRIVIAL(fatal) << "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 */
if (vm.count("verbose")) {
printf("Starting mainWindow\n");
}
int result = mainWindow(&shaderProgram);
return result;
@ -81,6 +88,7 @@ void help(char *prog, po::options_description desc) {
<< "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

View file

@ -1,13 +1,17 @@
#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 <boost/log/trivial.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;
@ -15,3 +19,4 @@ using namespace std;
int main(int argc, char **argv);
void help(char *prog, po::options_description desc);
#endif