Send video texture to shader?

I’ve done this before, but in previous version of oF (0.8.4 and 0.9.0).

Basically, I have a fragment shader that inverts the colors of a texture.

I want to run this on a video (ofVideoPlayer loading 640x480 h264 .mp4)

here’s my code:
in setup

shader.load("","shader.frag");

in draw

if (bInvert){
        shader.begin();
        shader.setUniform2f("u_resolution",_w,_h);
        shader.setUniformTexture("u_tex0",bgVid->getTexture(),0);
        ofDrawRectangle(0,0,_w,_h); // draw shader
        shader.end();
}

But I get the error:

[ error ] ofTexture: getTextureData(): texture has not been allocated

I’ve also tried setting the uniform texture number to 1, same issue

any thoughts?

Ok - I tried drawing the video into an fbo, and am passing the fbo texture to the shader
No error now, but I’m not seeing my texture from the shader.

Here’s my shader code:

#version 120

uniform sampler2D u_tex0;
uniform vec2 u_resolution;

void main () {
    vec2 st = gl_FragCoord.xy/u_resolution.xy;
    vec4 color = vec4(st.x,st.y,0.,1.);

    color = texture2D(u_tex0,st);
    color.rgb = 1.-color.rgb;

    gl_FragColor = color;
}

Here’s my draw code:

if (bInvert){
    bgFbo.begin();
    ofClear(0);
    bgVid->draw(0,0,_w,_h);
    bgFbo.end();
    shader.begin();
    shader.setUniform2f("u_resolution",_w,_h);
    shader.setUniformTexture("u_tex0",_bgFbo.getTexture(),1);
    ofDrawRectangle(0,0,_w,_h); // draw shader
    shader.end();
}

It draws white (if I remove the color.rgb = 1.-color.rgb; line, it draws black).
I know the fbo contains the video texture, as I’ve tried drawing that separately.

Ok - solved for now… but still seems like there’s a bug (?) in passing the video texture to the shader
i.e.

[ error ] ofTexture: getTextureData(): texture has not been allocated

That might be due to AVFoundationPlayer?

In any case, the solution for that was to draw the video into an fbo and pass the fbo texture to the shader.

For the shader issue itself (not drawing the texture) - I realized in the past I’ve used ofDisableArbTex() in order to use sampler2D. Instead I’m now using sampler2DRect, per below:

invert.frag

#version 120

uniform sampler2DRect u_tex0;
uniform vec2 u_resolution;

void main () {
	vec2 st = gl_FragCoord.xy/u_resolution; // normalize coords
	st.y = 1.-st.y; // invert y to draw normally per openFrameworks
	st *= u_resolution; // de-normalize coords
    vec4 color = vec4(st.x,st.y,0.,1.);

    color = texture2DRect(u_tex0,st); // grabs texture data using non-normalized coords
    color.rgb = 1.-color.rgb;

    gl_FragColor = color;
}