GLSL- Unable to load texture properly

Hello to everyone.
I’m currently trying to display a simple texture (grabbed from an ofVideoPlayer) and applaying into a rectangle using a GLSL shader, the main problem is the texture appears to be monochrome, i can only see various shades of grey and not the whole texture, am i missing something? i’m really a beginner in GLSL programming, perhaps someone could help me.

Here’s the main code:

void draw() {
ofSetColor(ofColor::white);
shader.begin();
shader.setUniformTexture(“tex”, videoPlayer.getTexture(), 0);
ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight());
shader.end();
};

the vertex shader:

uniform mat4 modelViewProjectionMatrix;

in vec4 position;
in vec2 texcoord;
out vec2 texCoordVarying;

void main()
{
texCoordVarying = texcoord;
gl_Position = modelViewProjectionMatrix * position;
}

and the fragment shader:

uniform sampler2DRect tex;

in vec2 texCoordVarying;

out vec4 outputColor;

void main()
{
vec3 rgb = texture(tex, texCoordVarying.xy).rgb;
outputColor = vec4(rgb, 1.0f);
}

a rectangle drawn using ofDrawRectangle doesn’t have texture coordinates, you would need to create your own rectangle using ofMesh or just use ofMesh::plane to create an ofMesh of a plane with texture coordinates, normals…

Thanks arturo for the fast reply, i’ve tryied using ofMesh::plane to create a plane with texture coordinates, but the problem still occurs, i’ve got the same monochrome texture applied to the plane

I think you should call “ofDisableArbTex()” in setup()

if you wanna just display a video for a whole screen then just use gl_FragCoord.

in fragment,

(if you called ofDisabledArbTex())
uniform sampler2D tex;
(else)
uniform sampler2DRect tex;

void main(){
    (if you called ofDisabledArbTex())
    vec3 rgb =  texture2D(tex, gl_FragCoord.xy/yourScreenResolution).rgb;
    (else) 
    vec3 rgb =  texture2DRect(tex, gl_FragCoord.xy).rgb;
    outputColor = vec4(rgb, 1.0f);
}

Thanks to everyone, now it finally works! :grinning:
I’ve got another question to ask, what i have to do in order to applying the texture, for example, into a sphere?

If you’ve succeeded drawing texture onto ofMesh::plane, than it should work the same way with ofMesh::sphere.