How to use (simulate) a GL_TEXTURE_RECTANGLE in the ES 3.0

Hello!
I am porting OpenGL to OpenGL ES 3.0 and have run into a problem in the form GL_TEXTURE_RECTANGLE. please tell me the solution.

See the last line on this wiki page:

For the simplest usage, you just convert 0…N texture coordinates to 0…1, pass the texture unit ID into the shader via a sampler2D instead of a sampler2DRECT, and of course on the C++ side, create+bind the texture using GL_TEXTURE_2D instead of GL_TEXTURE_RECTANGLE.

If you need more info, feel free to post the GLSL code snippet (including sampler declaration) that you’re trying to convert.

Thank you,

uniform sampler2DRect tex0;
...
void main(void)
{
...       
       vec4 vals = texture2DRect(tex0, tc);

Ok, yes. That’s the simplest usage of rectangle textures.

Also given that you are calling texture2DRect() to sample the texture and not texture(), it appears that your shader is targeting GLSL <= 1.20.

In newer GLSL versions and in GLSL-ES > 1.0, you’ll want to call texture() here instead. Also in these newer versions, you can use the textureSize() function in the shader to convert your texture coordinates to 0…1.

texture2DRect for clarity.

ok, it is right?:

#version 300 es
uniform sampler2D tex0;
...
void main(void)
 {
...
      ivec2 textureSize2d = textureSize(tex0, 0);
      vec4 vals = texture(tex0, vec2(tc.x / textureSize2d.x, tc.y / textureSize2d.y);

...

Looks like it. If not, it’s pretty close.

You may have already, but be sure to set your texture min filter to one which doesn’t use MIPmaps (since your texture doesn’t have them). GL_NEAREST or GL_LINEAR will do.

Thank you very much.
I use verified open source code where the texture is defined as GL_TEXTURE_RECTANGLE -> doesn’t use MIPmaps and GL_NEAREST or GL_LINEAR

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.