How to flip Y axis of the texcoord in OpenGL ARB shader?

Viewed 89

It can be displayed normally with the shader below, but the image is upside down.

!!ARBfp1.0
TEX result.color, fragment.texcoord, texture[0], RECT;
END

So I'am trying to flip the Y-axis of the texcoord, like:

!!ARBfp1.0
TEMP uv;
MOV uv, fragment.texcoord;
ADD uv.y, 1.0, -fragment.texcoord.y;
TEX result.color, uv, texture[0], RECT;
END

It not work. I am not familiar with OpenGL ARB assembly language.

I found the reference of the TEX instruction here, it says

Takes the first three components of the source vector to sample from the specified texture target on the specified texture image unit.

I doubt that fragment.texcoord is the same as texcoord in GLSL, where sampling coordinates only use two components.

1 Answers

You are using RECT as texture target (as opposed to e.g. 2D), so your Y texture coordinate do not range from [0.0..1.0), but from [0.0..texture height). So, your computation of ADD uv.y, 1.0, -fragment.texcoord.y is wrong.

Related