Then I add my base vert code,it’s easy ,and i will chang change below.
varying vec2 texCoordVarying;
void main()
{
vec2 texcoord = gl_MultiTexCoord0.xy;
texCoordVarying = vec2(texcoord.x , texcoord.y);
// send the vertices to the fragment shader
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
At last it‘s my frag code
uniform sampler2DRect BaseImage;
varying vec2 texCoordVarying;
void main (void)
{
vec2 st = texCoordVarying.st;
vec4 base = texture2DRect(BaseImage, st);
gl_FragColor = base;
}
Yeah,it work very well!
But I doubt that why the _uwidth and _uheight have to set that 600,I think _uwidth and _uheight should be range form 0 to 1. Then I can give shader different size texture, and then just find the pixel on the texture in proportion.
By default OF makes use of ARB textures, which basically means that you need to pass “pixel coordinates” instead of normalized coordinates.
You can use ofEnableArbTex() and ofDisableArbTex() to switch between the two modes; just keep in mind that, if you want to use 0-1 coords with a specific texture, you’ll need to call ofDisableArbTex() before allocating it.
In order to work with non ARB textures you should:
call ofDisableArbTex() before allocating/using the textures (i.e. in setup() or calling the enable/disable functions whenever you need a specific behaviour for a specific texture)
in your fragment shader, you should use sampler2D instead of sampler2DRect (you can also use both in the same shader, the important thing is that you use the right one with the correct texture type)
If you follow these rules it should work fine.
As for your last question: you can use ARB textures with different texture sizes simply passing the texture resolutions as uniform arguments. I used this technique in cases where I needed a fragment shader that used information in one texture to apply rules in another one and the ratio of the 2 textures where relevant too (i.e.: sprite maps, gpu computing…)
and in the shader:
…
uniform sampler2DRect tex;;
uniform sampler2DRect tex1;
uniform vec2 texSize;
uniform vec2 tex1Size;
…
vec2 tc = gl_TexCoord[0].st;
vec4 texelMain = texture2DRect(tex,tc);
//let’s say you want to spread texture1 over texture: you simply make a ratio
vec2 tt = tc/texSize*tex1Size;
vec4 texelMapped = texture2DRect(tex,tc);
…