Search code examples
opengl-esglsltexture2d

OpenGL ES 2.0 Texture2D indexing


I understand how texture2D works in general. My question is more specific.

In the code fragment:

  texture2D(sTexture, texCoord.st)

Are texCoord.s and texCoord.t between [0, 1], or

Do they have a square size, or

Do they have the image size?

If they are not [0, 1], what is the point of having the coordinates s, t to be floats?


Solution

  • Texcoords are normalized floats (range [0,1]) in the normal case, and unnormalized floats (range [0,w] or [0,h], respecitvely) in the case of GL_TEXTURE_RECTANGLE.

    The texcoords are never integer when sampling from it, but always floating point since not a specific texel is fetched, but the texture is sampled at some location, not just the texel centers. So during sampling, the texels define rectangluar patches in texture space, and the texture filter will define the sampling function to use define a resulting color for every location in the whole texture space. For example, GL_LINEAR will do a linear interpolation between neighboring texels if you sample inbetween their texel centers.