Skip to content

Instantly share code, notes, and snippets.

@fkaa
Created August 21, 2014 18:10
Show Gist options
  • Select an option

  • Save fkaa/3caa9b53762d42b741b4 to your computer and use it in GitHub Desktop.

Select an option

Save fkaa/3caa9b53762d42b741b4 to your computer and use it in GitHub Desktop.
GLuint Program::load_shader(const char* path, GLenum type) {
std::vector<char> data;
if (FILE* fp = fopen(path, "r")) {
char buf[1024];
while (size_t len = fread(buf, 1, sizeof(buf), fp)) {
data.insert(data.end(), buf, buf + len);
}
fclose(fp);
}
const char* src = &data[0];
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &src[0], NULL);
glCompileShader(shader);
GLint source_status = GL_FALSE, log_len;
glGetShaderiv(shader, GL_COMPILE_STATUS, &source_status);
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len);
if (log_len > 0) {
std::vector<char> shader_error(log_len);
glGetShaderInfoLog(shader, log_len, NULL, &shader_error[0]);
Log::e("%s", &shader_error[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment