load shaders (broken)

This commit is contained in:
Christoph J. Scherr 2023-10-19 16:15:28 +02:00
parent b3acf81398
commit 2c393b1851
3 changed files with 31 additions and 6 deletions

View File

@ -18,7 +18,20 @@ string ShaderProgram::baseName() {
} }
ShaderProgram::ShaderProgram(Base base, string vertexSource, 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; } int ShaderProgram::run() { return 255; }
@ -26,8 +39,7 @@ void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
} }
/* extended main function */ int initGl() {
int mainWindow(ShaderProgram* shaderProgram) {
/* graphics stuff */ /* graphics stuff */
glfwInit(); glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
@ -39,16 +51,20 @@ int mainWindow(ShaderProgram* shaderProgram) {
if (window == NULL) { if (window == NULL) {
printf("Failed to create GLFW window\n"); printf("Failed to create GLFW window\n");
glfwTerminate(); glfwTerminate();
return -1; return EXIT_GL;
} }
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
printf("Failed to initialize GLAD\n"); printf("Failed to initialize GLAD\n");
return -1; return EXIT_GL;
} }
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
return 0;
}
int mainWindow(ShaderProgram *shaderProgram) {
int result = shaderProgram->run(); int result = shaderProgram->run();

View File

@ -18,4 +18,5 @@ protected:
Base base; Base base;
}; };
int mainWindow(ShaderProgram* shaderProgramm); int mainWindow(ShaderProgram* shaderProgramm);
int initGl();
#endif #endif

View File

@ -5,6 +5,9 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
/* declarations */
int result = 0;
/* Parsing CLI Arguments */ /* Parsing CLI Arguments */
po::options_description desc("Available options"); po::options_description desc("Available options");
desc.add_options()("help,h", "show help")("verbose,v", "more verbose output")( 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"; 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 */ /* setup the shader program */
BOOST_LOG_TRIVIAL(trace) << "Reading shader files"; BOOST_LOG_TRIVIAL(trace) << "Reading shader files";
ifstream vertexFileStream(vm["vert"].as<string>()); ifstream vertexFileStream(vm["vert"].as<string>());
@ -76,7 +83,8 @@ int main(int argc, char **argv) {
/* Run our main program */ /* Run our main program */
BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow"; BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow";
int result = mainWindow(&shaderProgram); result = mainWindow(&shaderProgram);
/* if (result != 0) { return EXIT_GL;} */
return result; return result;
} }