Last active
August 29, 2015 14:04
-
-
Save niksaak/68215930f87a95458d16 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
const char* vertShader = R"( | |
#version 150 | |
uniform mat4 project; | |
uniform mat4 modelview; | |
in float x; | |
in float y; | |
in float z; | |
void main() { | |
gl_Position = project * modelview * vec4(x, y, z, 1.0); | |
} | |
)" | |
const char* fragShader = R"( | |
#version 150 | |
out vec4 gl_FragColor; | |
void main() { | |
gl_FragColor = vec4(0.2, 1.0, 0.2, 1.0); | |
} | |
)" | |
GLenum loadShaderProgram(void) { | |
// create handles for shader objects | |
auto vert = glCreateShader(GL_VERTEX_SHADER); | |
auto frag = glCreateShader(GL_FRAGMENT_SHADER); | |
// load source strings | |
glShaderSource(vert, 1, &vertShader, NULL); | |
glShaderSource(frag, 1, &fragShader, NULL); | |
// compile source into shader objects | |
glCompileShader(vert); | |
glCompileShader(frag); | |
// create a handle for shading program | |
auto program = glCreateProgram(); | |
// attach shader objects | |
glAttachShader(program, vert); | |
glAttachShader(program, frag); | |
// link shader objects into a program | |
glLinkProgram(program); | |
// use fresh compiled program for rendering | |
glUseProgram(program); | |
return program; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment