Skip to content

Instantly share code, notes, and snippets.

@btipling
Forked from xaxxon/graphics.cpp
Created April 6, 2016 06:06
Show Gist options
  • Save btipling/93785fb4b35594efa7def1b95fef1f75 to your computer and use it in GitHub Desktop.
Save btipling/93785fb4b35594efa7def1b95fef1f75 to your computer and use it in GitHub Desktop.
shader builder
GLuint Graphics::build_shader_program(const char * vertex_shader_source, const char * fragment_shader_source) {
// printf("Compiling shaders %s and %s\n", vertex_shader_source, fragment_shader_source);
/* create program object and attach shaders */
GLuint program = glCreateProgram();
shaderAttach(program, GL_VERTEX_SHADER, vertex_shader_source);
check_error(__FILE__, __LINE__);
shaderAttach(program, GL_FRAGMENT_SHADER, fragment_shader_source);
check_error(__FILE__, __LINE__);
GLsizei result;
/* link the program and make sure that there were no errors */
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &result);
if(result == GL_FALSE) {
GLint length;
char *log;
/* get the program info log */
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
log = (char *)malloc(length);
glGetProgramInfoLog(program, length, &result, log);
/* print an error message and the info log */
fprintf(stderr, "sceneInit(): Program linking failed: %s\n", log);
free(log);
/* delete the program */
glDeleteProgram(program);
program = 0;
return program;
}
return program;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment