Hi
Its possible to use in the same shader square and non square textures?
Also if i want to use the two i need to have two different texture coordinates (one for square and another one from non square)
So for example, can i do this¿?
in vertex:
varying vec4 texcoord;
uniform sampler2DRect myNonSquareText;
texcoord = gl_ModelViewProjectionMatrix * gl_Vertex;
in frag:
uniform sampler2DRect myNonSquareText;
gl_FragColor = texture2DRect(myNonSquareText, texcoord);
Im asking because i might be doing something wrong because i don’t get the color only black, and i don’t get any warning on the console… So im a bit lost
Thanksss
Hi there!
Yes, it is. But the result depends if you re using GL_TEXTURE_RECTANGLE_ARB or GL_TEXTURE_2D.
In the first case, it will apply the texture in “pixel size”. If you are applying the texture to larger surface, it’ll use the default wrap.
In the second case, it’ll normalize and interpolated the coords. So you texture can get stretched. It depends on the ratio between the original texture and the final quad into which you render.
Since you are using GL_TEXTURE_RECTANGLE_ARB and openGL 2.1, your shaders can be something like:
#version 120
varying vec2 texCoordVarying;
void main() {
texCoordVarying = gl_MultiTexCoord0.xy;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#version 120
varying vec2 texCoordVarying;
uniform sampler2DRect yourTexture;
uniform vec2 widthHeight;
void main(){
gl_FragColor = texture2DRect(yourTexture, texCoordVarying * widthHeight);
}
1 Like