Question about texelFetch


i have question about texelfecth function. so i have a data that contain textures, its an array of unsigned char and i fill the data with

if(index % 3 == 0) value[index] = 250;
else value[index] = 0;

and the filling process is valid, i print the data it prints

250, 0, 0, 250, 0, 0

the data is 172563 unsigned char, so it means i have texture with width and height 17 and 256 respectively. i sent the data by calling this:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 17, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, mapFit);

i think nothing wrong until this step, right?

no in the glsl i fill my pixel by using texelFetch, let say i fill all the texture with the same texel from the texture:

vec4 colorMap = vec4(texelFetch(texMap, ivec2(6, 4), 0));

the problem is it shows blue instead of red. but if put a y value that dividalbe by 3 (y%3 == 0) it gives red value. but y%1 is blue and y%2 is green. whats wrong with my code? shouldnt it be all red since i enter the internal format as GL_RGB8? any1 notice anything wrong with my code?

thanks in advance

Try glPixelStorei(GL_UNPACK_ALIGNMENT, 1)

Read the glPixelStore documentation. In particular GL_UNPACK_ALIGNMENT, which defaults to 4.

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