hello:
I’m new in openframeworks and GLSL too.
in my program I use shaders to run on the Raspberry Pi"s GPU…, … but I run that, I get the following error:
[warning] ofShader: GL_FRAGMENT_SHADER shader reports:
Compiled
[Error] ofShader: checkProgramLinkStatus (): program failed to link
[Error] ofShader: program reports:
ERROR: SEMANTIC-26 (fragment shader, line 9) Illegal field selector (eg using .z with a vec2)
and still have not found the problem in the code,
here the fragment and vertex shader program, and the ofApp.cpp .:
/ vertex shader
attribute vec4 position; // set automatically by OF
attribute vec4 normal; // set automatically by OF
attribute vec2 texcoord; // set automatically by OF
uniform mat4 modelViewMatrix; // set automatically by OF
uniform mat4 projectionMatrix; // set automatically by OF
uniform float time;
void main(){
vec4 pos = projectionMatrix * modelViewMatrix * position;
gl_Position = pos;
}
Fragment shader (error in this shader when it runs)
precision highp float;
uniform sampler2D texture0;
uniform float time;
void main(){
//Getting the coordinates of the current pixel in texture
vec2 pos = gl_FragColor[0].st;
float displacementHeight = 5.0;
//Changing pos by sinewave
float displacementY = sin(time + (pos.x / 350.0)) * displacementHeight;
//Shifting x-coordinate
//Getting pixel color from texture tex0 in position pos
vec2 modifiedPosition = pos;
modifiedPosition.y += displacementY;
vec4 color = texture2D(texture0, modifiedPosition);
//Output of shader
gl_FragColor = color;
}
with the src code (ofApp.cpp, etc it compile fine)
void ofApp::draw(){
//Draw background video
ofBackground(0);
ofSetColor( 255, 255, 255 );
float time = ofGetElapsedTimef();
float duration = (9*n) / 1.0; // al fin de cuentas es una duracion en segundos, uniforme
float pos = fmodf( time, duration );
int i = int( pos / duration * n );
ofImage img = seq[i];
fbo.begin();
ofBackground(0);
ofSetColor(255,255,255);
img.draw( 0, 0 );
fbo.end();
// Ahora el Shader
shader.begin();
shader.setUniform1f("time", ofGetElapsedTimef());
ofSetColor(255,255,255);
fbo.draw(0,0);
shader.end();
}
I pass to the shader a rectangle texture, and with the fragment shader I take de color in gl.FragCoor.0, an wok with that using trigonometric function…the effect is like a air waving a flag… in my Desk computer, the program is perfect, but, that use openGL 2.0, and the Pi uses openGL ES, so I rewrote the code using the variables described in openGL ES. but not work yet
Thanks in advance,
best regards