Am I missing something really obvious here ?
(Win2K; GeForceFX 5700LE)
I’m filling up a 16164 array with values, creating a texture from it, reading that texture back to another array, and then comparing the two arrays (original and reread). Why are they not the same ?
Thanks - RS.
int tex_size_x = 16, tex_size_y = 16;
int num_bytes = tex_size_x * tex_size_y * 4;
size_t mem_size = num_bytes * sizeof(GLubyte);
GLubyte* OriginalArray = (GLubyte*) malloc(mem_size);
GLubyte* ReadBackArray = (GLubyte*) malloc(mem_size);
for (unsigned int bi=0; bi<num_bytes; bi++) {OriginalArray[bi] = bi%255;}
// Initialize Texture
unsigned int texture_id;
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, 4, tex_size_x, tex_size_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, OriginalArray);
glDisable(GL_TEXTURE_2D);
// ... some stuff
// Read texture into ReadBackArray
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture_id);
glGetTexImage( GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, ReadBackArray);
glDisable(GL_TEXTURE_2D);
Should OriginalArray and ReadBackArray be the same here ? (they’re not - see below)
[texel_pos] : (OriginalRGBA) -> (RereadRGBA)
[0][0] : (0, 1, 2, 3)->(0, 0, 0, 0)
[0][1] : (4, 5, 6, 7)->(0, 0, 0, 0)
[0][2] : (8, 9, 10, 11)->(0, 0, 0, 0)
[0][3] : (12, 13, 14, 15)->(0, 0, 0, 0)
[0][4] : (16, 17, 18, 19)->(17, 17, 17, 17)
[0][5] : (20, 21, 22, 23)->(17, 17, 17, 17)
[0][6] : (24, 25, 26, 27)->(17, 17, 17, 17)
[0][7] : (28, 29, 30, 31)->(17, 17, 17, 17)
[0][8] : (32, 33, 34, 35)->(34, 34, 34, 34)
[0][9] : (36, 37, 38, 39)->(34, 34, 34, 34)
[0][10] : (40, 41, 42, 43)->(34, 34, 34, 34)
[0][11] : (44, 45, 46, 47)->(34, 34, 34, 34)
[0][12] : (48, 49, 50, 51)->(51, 51, 51, 51)
[0][13] : (52, 53, 54, 55)->(51, 51, 51, 51)
[0][14] : (56, 57, 58, 59)->(51, 51, 51, 51)
[0][15] : (60, 61, 62, 63)->(51, 51, 51, 51)
[1][0] : (64, 65, 66, 67)->(68, 68, 68, 68)
[1][1] : (68, 69, 70, 71)->(68, 68, 68, 68)
etc etc