linker hell

This commit is contained in:
Christoph J. Scherr 2023-10-18 17:03:13 +02:00
parent ee15e3ccaa
commit f0cb371955
4 changed files with 52 additions and 39 deletions

View File

@ -5,7 +5,6 @@ add_subdirectory(lib/glfw)
include_directories( include_directories(
include/ include/
lib/glad/include/
lib/glfw/include/ lib/glfw/include/
) )
file( file(

View File

@ -1,23 +1,28 @@
#include <glad/glad.c>
// glad must be loaded before GLFW
#include <GLFW/glfw3.h>
#include "graphics.hpp" #include "graphics.hpp"
#include <iostream> #include <iostream>
#include <unistd.h> #include <fstream>
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) { void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
} }
int mainWindow() { int mainWindow(ShaderProgram shaderProgram) {
/* graphics stuff */ /* graphics stuff */
glfwInit(); glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
@ -40,24 +45,8 @@ int mainWindow() {
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 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}; int result = shaderProgram.run();
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();
}
glfwTerminate(); glfwTerminate();
return 0; return result;
} }

View File

@ -1 +1,23 @@
int mainWindow(); #ifndef GRAPHICS_HPP
#define GRAPHICS_HPP
#include <glad/glad.c>
// glad must be loaded before GLFW
#include <GLFW/glfw3.h>
#include <iostream>
#include <string>
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

View File

@ -3,7 +3,6 @@
#include <boost/program_options/positional_options.hpp> #include <boost/program_options/positional_options.hpp>
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
#include <exception>
#include <iostream> #include <iostream>
#include "graphics.hpp" #include "graphics.hpp"
@ -19,11 +18,9 @@ int main(int argc, char **argv) {
/* Parsing CLI Arguments */ /* Parsing CLI Arguments */
po::options_description desc("Available options"); po::options_description desc("Available options");
desc.add_options() desc.add_options()("help,h", "show help")("verbose,v", "more verbose output")(
("help,h", "show help") "vert", po::value<string>()->required(), "vertex shader file")(
("verbose,v", "more verbose output") "frag", po::value<string>()->required(), "fragment shader file");
("vert", po::value<string>()->required(), "vertex shader file")
("frag", po::value<string>()->required(), "fragment shader file");
/* unused for now */ /* unused for now */
po::positional_options_description pdesc; po::positional_options_description pdesc;
@ -55,15 +52,21 @@ int main(int argc, char **argv) {
printf("verbose!"); printf("verbose!");
} }
/* setup the shader program */
ShaderProgram* shaderProgram = new ShaderProgram(
ShaderProgram::Base::Empty, vm["vert"].as<string>(), vm["frag"].as<string>());
/* Run our main program */ /* Run our main program */
int result = mainWindow(); int result = mainWindow(shaderProgram);
return result; return result;
} }
void help(char *prog, po::options_description desc) { void help(char *prog, po::options_description desc) {
cout << "Usage:" << endl cout << "Usage:" << endl
<< prog << " [-vh] [--vert] shaders/vertex.glsl [--frag] shaders/fragment.glsl" << prog
<< endl << endl << " [-vh] [--vert] shaders/vertex.glsl [--frag] shaders/fragment.glsl"
<< endl
<< endl
<< desc << endl; << desc << endl;
} }