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/
lib/glad/include/
lib/glfw/include/
)
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 <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) {
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;
}

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/variables_map.hpp>
#include <exception>
#include <iostream>
#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<string>()->required(), "vertex shader file")
("frag", po::value<string>()->required(), "fragment shader file");
desc.add_options()("help,h", "show help")("verbose,v", "more verbose output")(
"vert", po::value<string>()->required(), "vertex shader file")(
"frag", po::value<string>()->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<string>(), vm["frag"].as<string>());
/* 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;
}