# How to use GLSL texelFetch?

I have read the OpenGl documentation of texelFetch, which is:

gvec4 texelFetch(gsampler2D sampler, ivec2 P, int lod).

I know the first argument "sampler" is just a texture. But I am very confused about the second and third arguments.

According to the documentation, the second argument "P" is a texture coordinate. But it has the type ivec2, which means that it is a vector of integers. Shouldn't a texture coordinate be in the range [0, 1]?

And for the third argument "lod", in the documentation, it said "If present, specifies the level-of-detail within the texture from which the texel will be fetched." I have no idea how to set this argument...

Could anyone explain this and give a real example of how to use texelFetch?

Thank you!

For lod, it means the level of detail in the mipmap. We can simply use 0 for the base level (the original size).
Thus, an example of using texelFetch() should be:
vec4 texelValue= texelFetch(texture2D, ivec2(gl_FragCoord.xy), 0);