diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f57cb5..f161bb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ add_subdirectory(lib/glfw) include_directories( include/ - lib/glad/include/ lib/glfw/include/ ) file( diff --git a/src/graphics.cpp b/src/graphics.cpp index 303a0aa..2161ac7 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -1,23 +1,28 @@ -#include -// glad must be loaded before GLFW -#include - #include "graphics.hpp" #include -#include +#include + +using namespace std; + +string ShaderProgram::baseName() { + switch (this->base) { + case Empty: + return "Empty"; + case Triangle: + return "Triangle"; + } +} + +ShaderProgram::ShaderProgram(Base base, string vertexFile, string fragFile) { -void processInput(GLFWwindow *window) { - // if user presses ESC, close the window - if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) - glfwSetWindowShouldClose(window, true); } void framebuffer_size_callback(GLFWwindow *window, int width, int height) { glViewport(0, 0, width, height); } -int mainWindow() { +int mainWindow(ShaderProgram shaderProgram) { /* graphics stuff */ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); @@ -40,24 +45,8 @@ int mainWindow() { glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); - float vertices[] = {-0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f}; - - unsigned int VBO; - - glGenBuffers(1, &VBO); - glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); - - while (!glfwWindowShouldClose(window)) { - processInput(window); - - glClearColor(0.8f, 0.4f, 0.1f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - - glfwSwapBuffers(window); - glfwPollEvents(); - } + int result = shaderProgram.run(); glfwTerminate(); - return 0; + return result; } diff --git a/src/graphics.hpp b/src/graphics.hpp index 1975dcf..f7d826f 100644 --- a/src/graphics.hpp +++ b/src/graphics.hpp @@ -1 +1,23 @@ -int mainWindow(); +#ifndef GRAPHICS_HPP +#define GRAPHICS_HPP +#include +// glad must be loaded before GLFW +#include + +#include +#include + +class ShaderProgram { +public: + enum Base { Empty, Triangle }; + std::string baseName(); + ShaderProgram(Base base, std::string vertexFile, std::string fragFile); + int run(); + +protected: + unsigned int vertex; + unsigned int frag; + Base base; +}; +int mainWindow(ShaderProgram* shaderProgramm); +#endif diff --git a/src/main.cpp b/src/main.cpp index fb420e7..7a25611 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include "graphics.hpp" @@ -19,11 +18,9 @@ int main(int argc, char **argv) { /* Parsing CLI Arguments */ 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"); + 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"); /* unused for now */ po::positional_options_description pdesc; @@ -55,15 +52,21 @@ int main(int argc, char **argv) { printf("verbose!"); } + /* setup the shader program */ + ShaderProgram* shaderProgram = new ShaderProgram( + ShaderProgram::Base::Empty, vm["vert"].as(), vm["frag"].as()); + /* Run our main program */ - int result = mainWindow(); + int result = mainWindow(shaderProgram); return result; } void help(char *prog, po::options_description desc) { cout << "Usage:" << endl - << prog << " [-vh] [--vert] shaders/vertex.glsl [--frag] shaders/fragment.glsl" - << endl << endl + << prog + << " [-vh] [--vert] shaders/vertex.glsl [--frag] shaders/fragment.glsl" + << endl + << endl << desc << endl; }