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

View File

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

View File

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