build and use shader program

This commit is contained in:
Christoph J. Scherr 2023-10-21 19:26:45 +02:00
parent fd7f680592
commit 3c36684f41
2 changed files with 22 additions and 2 deletions

View File

@ -54,8 +54,8 @@ ShaderProgram::ShaderProgram(Base base, string vertexSource,
string fragSource) { string fragSource) {
int success; int success;
char infoLog[512]; char infoLog[512];
const char* vertexSource_c = vertexSource.c_str(); const char *vertexSource_c = vertexSource.c_str();
const char* fragSource_c = fragSource.c_str(); const char *fragSource_c = fragSource.c_str();
this->base = base; this->base = base;
BOOST_LOG_TRIVIAL(info) << "With base program \"" << this->baseName() << "\""; BOOST_LOG_TRIVIAL(info) << "With base program \"" << this->baseName() << "\"";
// NOTE: char arrays and char pointers are not actually the same. // NOTE: char arrays and char pointers are not actually the same.
@ -90,6 +90,25 @@ ShaderProgram::ShaderProgram(Base base, string vertexSource,
<< infoLog << std::endl; << infoLog << std::endl;
exit(EXIT_SHADER); exit(EXIT_SHADER);
} }
// combine it all in a actual program
this->program = glCreateProgram();
glAttachShader(this->program, this->vertex);
glAttachShader(this->program, this->frag);
glLinkProgram(this->program);
glGetProgramiv(this->program, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(this->program, 512, NULL, infoLog);
BOOST_LOG_TRIVIAL(fatal) << "could not link shader program:\n\n"
<< infoLog << std::endl;
exit(EXIT_SHADER);
}
// finalizing our setup
glUseProgram(this->program);
glDeleteShader(this->vertex);
glDeleteShader(this->frag);
} }
/** defines the base program behavior. /** defines the base program behavior.

View File

@ -17,6 +17,7 @@ protected:
unsigned int vertex; unsigned int vertex;
unsigned int frag; unsigned int frag;
Base base; Base base;
unsigned int program;
}; };
int mainWindow(ShaderProgram* shaderProgramm, GLFWwindow* window); int mainWindow(ShaderProgram* shaderProgramm, GLFWwindow* window);
GLFWwindow* initGl(); GLFWwindow* initGl();