View Full Version : question about texelFetch

02-03-2011, 06:57 PM

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 17*256*3 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

02-04-2011, 09:13 AM
Try glPixelStorei(GL_UNPACK_ALIGNMENT, 1)

02-04-2011, 10:25 AM
Read the glPixelStore documentation. In particular GL_UNPACK_ALIGNMENT, which defaults to 4.