From 2c393b18513d9c5d0c96098833965e1aa4449a6d Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 19 Oct 2023 16:15:28 +0200 Subject: [PATCH] load shaders (broken) --- src/graphics.cpp | 26 +++++++++++++++++++++----- src/graphics.hpp | 1 + src/main.cpp | 10 +++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/graphics.cpp b/src/graphics.cpp index fe50594..173f40e 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -18,7 +18,20 @@ string ShaderProgram::baseName() { } ShaderProgram::ShaderProgram(Base base, string vertexSource, - string fragSource) {} + string fragSource) { + BOOST_LOG_TRIVIAL(trace) << "creating empty shaders"; + this->vertex = glCreateShader(GL_VERTEX_SHADER); + this->frag = glCreateShader(GL_FRAGMENT_SHADER); + BOOST_LOG_TRIVIAL(trace) << "loading vertex shader"; + glShaderSource(this->vertex, 1, vertexSource.c_str(), + NULL); + BOOST_LOG_TRIVIAL(trace) << "compiling vertex shader"; + glCompileShader(this->vertex); + BOOST_LOG_TRIVIAL(trace) << "loading fragments shader"; + glShaderSource(this->frag, 2, fragSource.c_str(), NULL); + BOOST_LOG_TRIVIAL(trace) << "compiling fragments shader"; + glCompileShader(this->frag); +} int ShaderProgram::run() { return 255; } @@ -26,8 +39,7 @@ void framebuffer_size_callback(GLFWwindow *window, int width, int height) { glViewport(0, 0, width, height); } -/* extended main function */ -int mainWindow(ShaderProgram* shaderProgram) { +int initGl() { /* graphics stuff */ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); @@ -39,16 +51,20 @@ int mainWindow(ShaderProgram* shaderProgram) { if (window == NULL) { printf("Failed to create GLFW window\n"); glfwTerminate(); - return -1; + return EXIT_GL; } glfwMakeContextCurrent(window); if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { printf("Failed to initialize GLAD\n"); - return -1; + return EXIT_GL; } glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); + return 0; +} + +int mainWindow(ShaderProgram *shaderProgram) { int result = shaderProgram->run(); diff --git a/src/graphics.hpp b/src/graphics.hpp index 253dee3..79b9ab4 100644 --- a/src/graphics.hpp +++ b/src/graphics.hpp @@ -18,4 +18,5 @@ protected: Base base; }; int mainWindow(ShaderProgram* shaderProgramm); +int initGl(); #endif diff --git a/src/main.cpp b/src/main.cpp index e2f74c1..4ad11ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,9 @@ int main(int argc, char **argv) { + /* declarations */ + int result = 0; + /* Parsing CLI Arguments */ po::options_description desc("Available options"); desc.add_options()("help,h", "show help")("verbose,v", "more verbose output")( @@ -46,6 +49,10 @@ int main(int argc, char **argv) { BOOST_LOG_TRIVIAL(trace) << "verbose flag found, setting log level to trace"; } + /* init graphics stuff */ + result = initGl(); + if (result != 0) { return EXIT_GL;} + /* setup the shader program */ BOOST_LOG_TRIVIAL(trace) << "Reading shader files"; ifstream vertexFileStream(vm["vert"].as()); @@ -76,7 +83,8 @@ int main(int argc, char **argv) { /* Run our main program */ BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow"; - int result = mainWindow(&shaderProgram); + result = mainWindow(&shaderProgram); + /* if (result != 0) { return EXIT_GL;} */ return result; }