<<< GLSL #version number | Index | Shaders embedded in C++ >>> |
These functions are invoked during main initialization:
GLuint makeVertexShader(const char* shaderSource) { GLuint vertexShaderID = glCreateShader( GL_VERTEX_SHADER ); glShaderSource( vertexShaderID, 1, (const GLchar**)&shaderSource, NULL ); glCompileShader( vertexShaderID ); return vertexShaderID; } GLuint makeFragmentShader(const char* shaderSource) { GLuint fragmentShaderID = glCreateShader( GL_FRAGMENT_SHADER ); glShaderSource( fragmentShaderID, 1, (const GLchar**)&shaderSource, NULL ); glCompileShader( fragmentShaderID ); return fragmentShaderID; } GLuint makeShaderProgram (GLuint vertexShaderID, GLuint fragmentShaderID) { GLuint shaderProgramID = glCreateProgram(); glAttachShader( shaderProgramID, vertexShaderID ); glAttachShader( shaderProgramID, fragmentShaderID ); glLinkProgram( shaderProgramID ); return shaderProgramID; }
When rendering (or any time you want to activate the program), call
glUseProgram( shaderProgramID );
<<< GLSL #version number | Index | Shaders embedded in C++ >>> |