Created
July 16, 2015 00:17
-
-
Save anlsh/c081516b308515ecf4ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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