A simple fragment shader example
Consider a complete example of using the fragment shader in an openFrameworks project. It will be a base for other fragment shaders' examples. The shader here is pretty simple. It just inverts the colors of all the drawn pixels.
Note
This is example 08-Shaders/01-ShaderInverting
.
This example is based on the emptyExample
project in openFrameworks.
Creating the fragment shader
In the bin/data
folder, create a new text file shaderFrag.c
that contains the fragment shader's code as follows:
#version 120 #extension GL_ARB_texture_rectangle : enable #extension GL_EXT_gpu_shader4 : enable uniform sampler2DRect texture0; void main(){ //Getting coordinates of the current pixel in texture vec2 pos = gl_TexCoord[0].xy; //Getting the pixel color from the texture texture0 in pos vec4 color = texture2DRect(texture0, pos); //Changing the color - invert red, green, blue components color.r = 1.0 - color.r; color.g = 1.0 - color.g; color.b = 1.0 - color.b; ...