Shader cannot move texture x, y location Crossposted https://forum.openframeworks.cc/t/shader-cannot-move-texture-x-y-location/29395
Hello I am trying to move the x y location of the texture using this code but it doest not work.

//Fragment shader
#version 120
#extension GL_ARB_texture_rectangle : enable
#extension GL_EXT_gpu_shader4 : enable

uniform sampler2DRect texture0;

void main(){
    //Getting coordinates of the current pixel in texture
    vec2 pos = gl_TexCoord[0].xy;

    // pos.x = (pos.x/0.5); //working
    pos.x += 0.2 //&lt;-- not working how to fixed this?

    //Getting the pixel color from the texture texture0 in pos
    vec4 color = texture2DRect(texture0, pos);

    //Changing the color - invert red, green, blue components
    //color.r = 1.0 - color.r;
    color.g = 1.0 - color.g; //working..
    //color.b = 1.0 - color.b;

    //Output the color of shader
    gl_FragColor = color;
}




//Vertex shader
#version 120
#extension GL_ARB_texture_rectangle : enable
#extension GL_EXT_gpu_shader4 : enable

void main() {
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_FrontColor = gl_Color;
}


whats wrong with this code?
pos.x += 0.2 //not working how to fixed this?

////////////////////////////////////////////////////////////////////////

I found the solution  pos.x += 0.2 already working but it is not visible.
if I tried bigger number like  pos.x += 100 it is clear that the textures moves.
What you do is shifting the texture coordinates. This will move the texture on your polygon, and depending on your settings it will handle the borders which are now probably wrong. however, this will not move your polygon - if you want to move an entire object, you should not do that within the shader. you do that via modifying your model matrix.

I assume you have a rectangle, and you want to move it by 0.2 along the x axis. Then you would edit the correct element of your model matrix for the rectangle. 

//depending on your setup, you may need [0][3] rather than [3][0]
modelMatrix[3][0] += 0.2;
//now upload the matrix to your shader
//the entire object will be moved by 0.2 units 


If that is what you wanted, then you need to remove the fragment shader position calculation.

On a sidenote: I had problems with using += in a shader the other day, so it might just be that this doesn't compile. Try using position = position + 0.2; instead.