Implemented shader program headers

This commit is contained in:
CobaltXII
2018-12-28 15:38:59 -05:00
parent 019b00bf41
commit b7dc9317ba
3 changed files with 47 additions and 1 deletions

0
src/inc/program.cpp Normal file
View File

43
src/inc/program.hpp Normal file
View File

@@ -0,0 +1,43 @@
#include <iostream>
#include <string>
// Load a shader program from two files. One is a vertex shader, and one is a
// fragment shader. Geometry shader support is not implemented.
GLuint mc_load_program(std::string vertex_path, std::string fragment_path)
{
GLuint shader_program = glCreateProgram();
GLuint vertex_shader = mcu_load_shader(vertex_path, GL_VERTEX_SHADER);
GLuint fragment_shader = mcu_load_shader(fragment_path, GL_FRAGMENT_SHADER);
glAttachShader(shader_program, vertex_shader);
glAttachShader(shader_program, fragment_shader);
glLinkProgram(shader_program);
GLint success = 0;
glGetProgramiv(shader_program, GL_LINK_STATUS, &success);
if (!success)
{
std::cout << "Could not link shader program loaded from \"" << vertex_path << "\" and \"" << fragment_path << "\"." << std::endl;
GLchar crash_information[4096];
glGetProgramInfoLog(shader_program, 4096, NULL, crash_information);
std::cout << crash_information;
exit(10);
}
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
return shader_program;
}

View File

@@ -14,4 +14,7 @@
#include <SDL.h>
#include <shader.hpp>
#include <shader.cpp>
#include <shader.cpp>
#include <program.hpp>
#include <program.cpp>