-
Notifications
You must be signed in to change notification settings - Fork 1
Code examples | C API vs GL
sque edited this page Mar 13, 2013
·
1 revision
Here you can find some examples written in OpenGL C API and GL++ at the same time. You can see them to compare the two APIs by the "users" side.
OpenGL C API
// Prototype of a user function to load shader from file
int loadshader(char * filename, GLchar** ShaderSource, unsigned long* len);
GLuint vertexShader, fragmentShader, ProgramObject;
GLchar* shaderSource;
int shaderSourceLen;
vertexShaderObject = glCreateShader(GL_VERTEX_SHADER);
loadshader("shaderfile.vert", &shaderSource, &shaderSourceLen)
glShaderSource(vertexShader, 1, &shaderSource, &shaderSourceLen)
glCompileShader(vertexShader)
fragmentShaderObject = glCreateShader(GL_FRAGMENT_SHADER);
loadshader("shaderfile.frag", &shaderSource, &shaderSourceLen)
glShaderSource(vertexShader, 1, &shaderSource, &shaderSourceLen)
glCompileShader(vertexShader)
ProgramObject = glCreateProgram();
glAttachShader(ProgramObject, vertexShaderObject);
glAttachShader(ProgramObject, fragmentShaderObject);
glLinkProgram(ProgramObject);
Same on GL++
glpp::shared_program_t pprog;
pprog = new glpp::program();
pprog->attach_shader(glpp::open_shader_file(glpp::shader_type::VERTEX, "shaderfile.vert"));
pprog->attach_shader(glpp::open_shader_file(glpp::shader_type::FRAGMENT, "shaderfile.frag"));
pprog->build();
pprog->use();