texelFetchBuffer()

Hi,
I am newbie in OpenGL and need some help in texelFetchBuffer().

The second parameter is specified as index into texel array. But i am not able to understand how to use this function and the indexes.
I goggled it, but didn't get much info how to use it.
Please help me..

and fragment shader:
vec4 offset=texelFetch(out_offset,index);
Color = offset;
Now i am drawing GL_Traingle_fan and when i execute it, it draws square with 2 triangles one with white color and second with pink color. It is taking 3rd and 4th offset in pixel array instead taking each index for each vertex.

I want to draw square with each vertex having color of each index in pixels array. Please correct me where i am going wrong above..

First of all, let me correct my previous statement: [0, elements * sizeof(type) - 1] is not the range the indices will be in. Of course, it's simply [0, 1, ..., elements - 1]. It is true, however, that bufferSize = elements * sizeof(type) and that the real offset into the buffer is calculated by sizeof(type) * index.

Regarding your current issue: Why don't you simply fetch the color at the vertices where the indices are unique and uninterpolated? Simply move your fetch to the vertex shader and have the GPU interpolate the colors not the indices. I'm actually not sure at the moment how int values are interpolated but obviously they are not what you want afterwards.

First of all, let me correct my previous statement: [0, elements * sizeof(type) - 1] is not the range the indices will be in. Of course, it's simply [0, 1, ..., elements - 1]. It is true, however, that bufferSize = elements * sizeof(type) and that the real offset into the buffer is calculated by sizeof(type) * index.

Regarding your current issue: Why don't you simply fetch the color at the vertices where the indices are unique and uninterpolated? Simply move your fetch to the vertex shader and have the GPU interpolate the colors not the indices. I'm actually not sure at the moment how int values are interpolated but obviously they are not what you want afterwards.