ofxCvGrayscaleImage to Shader => black


#1

Hello there,

I’m using the ofxOpenCv addon and converting a video from the ofVideoGrabber in an ofxCvGrayScaleImage for contour finding. Now i want to pass that grayscale imagestream to my fragment shader. The problem: in the shader “r/g/b” will be displayed black (0) and “a” will be displayed white (1). I read that this is a kind of “glsl autofill” if it receives no values. (other texture passing works)

in of:

shader.setUniformTexture("uTex0", grayDiff.getTexture(), 0);

in fragment shader:

uniform sampler2DRect uTex0;
in vec2 vTexCoord;
out vec4 fragColor;
void main(){
    vec2 coord = vTexCoord;
    vec4 texture0 = texture(uTex0, coord);
    fragColor = vec4(texture0.r, texture0.g, texture0.b, 1.);
}

I also assumed that the channels are the problem, mentioned here. So i tried the following:

in of:

texture.allocate(960, 720, GL_RED);
texture = grayDiff.getTexture();
shader.setUniformTexture("uTex0", texture, 0);

I’m trying things for hours and not coming to a solution. Maybe I’m overlooking something? Hope for some help :slight_smile:

Thank you in advance,
David


#2

I handled it by converting the ofxCvGrayscaleImage into an ofImage.

image.setFromPixels(grayDiff.getPixels());
shader.setUniformTexture("uTex0", image.getTexture(), 0);

It works, but how to do it directly with an ofxCvGrayscaleImage?