Compare commits

...

1 Commits

Author SHA1 Message Date
Christoph J. Scherr 21caa8dd76 linker hell 2023-10-18 17:04:18 +02:00
4 changed files with 18 additions and 126 deletions

View File

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

View File

@ -1,63 +1,10 @@
#include <glad/glad.c>
// glad must be loaded before GLFW
#include <GLFW/glfw3.h>
#include "graphics.hpp"
#include <GLFW/glfw3.h> // Include the library header file here
#include <iostream>
#include <unistd.h>
void processInput(GLFWwindow *window) {
// if user presses ESC, close the window
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
void init() {
// Use GLFW functions here
}
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
glViewport(0, 0, width, height);
}
int mainWindow() {
/* graphics stuff */
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
GLFWwindow *window = glfwCreateWindow(800, 600, "Shader Loader", NULL, NULL);
if (window == NULL) {
printf("Failed to create GLFW window\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
printf("Failed to initialize GLAD\n");
return -1;
}
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();
}
glfwTerminate();
return 0;
void draw() {
// Use GLFW functions here
}

View File

@ -1 +1,9 @@
int mainWindow();
#ifndef GRAPHICS_HPP
#define GRAPHICS_HPP
#include <GLFW/glfw3.h> // Include the library header file here
void init();
void draw();
#endif

View File

@ -1,69 +1,7 @@
#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 <exception>
#include <iostream>
#include "graphics.hpp"
namespace po = boost::program_options;
using namespace std;
int main(int argc, char **argv);
void help(char *prog, po::options_description desc);
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");
/* unused for now */
po::positional_options_description pdesc;
// NOTE: if you want to add a positional argument,
// you need to create and option for it as it seems.
pdesc.add("vert", 1);
pdesc.add("frag", 1);
po::variables_map vm;
try {
po::store(po::command_line_parser(argc, argv)
.options(desc) // load options
.positional(pdesc) // load positionals
.run(),
vm);
po::notify(vm);
if (vm.count("help") || argc < 3) {
help(argv[0], desc);
return 1;
}
} catch (po::error &e) {
cout << e.what() << endl << endl;
help(argv[0], desc);
return 1;
}
if (vm.count("verbose")) {
printf("verbose!");
}
/* Run our main program */
int result = mainWindow();
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
<< desc << endl;
int main() {
init();
draw();
return 0;
}