O'Reilly logo

Mastering openFrameworks: Creative Coding Demystified by Denis Perevalov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required