Get texture color in fragment shader / texture reflected

HI! I have some problem with this basic shader.
I don’t know why, but i try to simply redraw my texture using fragment shader, but if i don’t flip vertically my y coord i see my image reflected.
Can somebody explain me why this happen?
(my image is 1000x400px, like my window)

testApp.cpp

#include "testApp.h"

void testApp::setup()
{
  ofSetVerticalSync(true);
	ofSetFrameRate(60);
	ofBackground(10, 10, 10);
  
  shader.load( "shader.vert", "shader.frag");
  ggpTest.loadImage("ggpTest.jpg");
}

void testApp::update()
{
}

void testApp::draw()
{
  shader.begin();
  shader.setUniformTexture("ggpTest", ggpTest.getTextureReference(), 1);
  ofRect(0, 0, ofGetWidth(), ofGetHeight());
  shader.end();
}

shader.vert

#version 150

uniform mat4 modelViewProjectionMatrix;

in vec4 position;

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

shader.frag

#version 150

out vec4 outputColor;
uniform sampler2DRect ggpTest;

void main()
{
  vec4 ggpTestColor = texture(ggpTest, vec2(gl_FragCoord.x, 400 - gl_FragCoord.y));
  outputColor = vec4(ggpTestColor);
}

I have the solution!
If i change the origin for gl_FragCoord​’s window-space, it works without strange tricks!
So, in my fragment shader i added this:

layout(origin_upper_left) in vec4 gl_FragCoord;
3 Likes

Hi @Mauro I’m having this same exact issue. My shader is a bit complex so I hesitate to copy/paste the entire thing here but the important parts are as follows:
.vert file

#version 120

void main()
{
    gl_Position = ftransform();
}

.frag file based on shadertoy shader

uniform vec3 iResolution;
uniform float iGlobalTime;
uniform vec4 iMouse;
uniform sampler2D iChannel0; // Texture #1

void main(void)
{
    
    vec2 uv =  gl_FragCoord.xy / iResolution.xy;

    vec3 color = vec3(red,green,blue);
  
    
    gl_FragColor = vec4(color,1.0);
    

}

Where exactly did you place ???

layout(origin_upper_left) in vec4 gl_FragCoord;

Thanks for posting this!