Skip to content

@andreweduffy /gist:4052017
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
OpenGL Fragment Shader
void InitShading(){
//Fragment shader we want to use
GLuint oddRowShaderId = glCreateShader(GL_FRAGMENT_SHADER);
std::cout << "Creating the fragment shader with id " << oddRowShaderId << std::endl;
const GLchar *source =
"void main(){"
" if (mod(gl_FragCoord.y-0.5, 2.0) == 1.0){"
" gl_FragColor = gl_Color;"
" } else {"
" gl_FragColor = vert4(0.0, 0.0, 0.0, 1.0);"
" }"
"}";
std::cout << "Shader source:\n" << source << std::endl;
std::cout << "Gathering shader source code" << std::endl;
glShaderSource(oddRowShaderId, 1, &source, 0);
std::cout << "Compiling the shader" << std::endl;
glCompileShader(oddRowShaderId);
std::cout << "Creating new glCreateProgram() program" << std::endl;
GLuint shaderProgramId = glCreateProgram(); //Shader program id
std::cout << "Attaching shader to the new program" << std::endl;
glAttachShader(shaderProgramId, oddRowShaderId); //Add the fragment shader to the program
std::cout << "Linking the program " << std::endl;
glLinkProgram(shaderProgramId); //Link the program
std::cout << "Using the program for rendering" << std::endl;
glUseProgram(shaderProgramId); //Start using the shader
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.