PDA

View Full Version : problem with building a texture from matrix



shapeare
06-22-2011, 05:18 AM
I want to build a texture from matrix, and then send it to a shader for computing.

for experiment, I constructed my matrix like the following:


for(int h = 0; h < height; h++)
for(int w = 0; w < width; w++)
{
id[h][w][0] = 0;
id[h][w][1] = 1;
id[h][w][2] = 2;
id[h][w][3] = 3;
}

and then use the glTexImage2D function call like this:


glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
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_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, id);


I used gDEBugger to check the value in the texture, and found some confusing results like the attached image. I cannot find any value equals 0, 1, 2, or 3. it is really confusing.

V-man
06-22-2011, 04:30 PM
Try using a 1 dimentional array.