Skip to content

Instantly share code, notes, and snippets.

@anlsh
Created July 16, 2015 00:17
Show Gist options
  • Save anlsh/c081516b308515ecf4ca to your computer and use it in GitHub Desktop.
Save anlsh/c081516b308515ecf4ca to your computer and use it in GitHub Desktop.
#include "Shaders.h"
t2d::Shader::Shader(const char * foo, GLenum type, int loadmode = LOAD_FROM_FILE) {
if (loadmode == LOAD_FROM_FILE) {
std::ifstream in(foo);
source = std::string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
glSource = (GLchar *) source.c_str();
} else if (loadmode == LOAD_FROM_STRING) {
glSource = (GLchar *) foo;
}
id = glCreateShader(type);
glShaderSource(id, 1, &glSource, NULL);
glCompileShader(id);
GLint success = 0;
glGetShaderiv(id, GL_COMPILE_STATUS, &success);
if (success != GL_TRUE) {
throw ShaderCompilationError();
}
}
t2d::Shader::~Shader() {
glDeleteShader(id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment