glReadPixels problem


I have a problem with my code, I hope somebody can help me:

In my code, I need to read some pixels and redraw them again. For example, a matrix of m*n pixels.

i can do it if I read one by one the pixels:

for(int x=0; x<m; x++)
for(int y=0; y<n; y++ )
glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &Color[y*m+x][0]);

and then draw them again in the screen (currently I do it with GL_POINTS), and it works (but is slow…)

but if I try to read all the pixels at the same time:
glReadPixels(0, 0, m, n, GL_RGB, GL_UNSIGNED_BYTE, &Color[0][0]);

when I draw again they aren’t in order. I have tried a lot of things and nothing works correctly, I think maybe the problem is that when you read more than one pixel with glReadPixels, they aren’t stored in order in my array, but i’m not sure.

Thanks so much for the help!

Try adding this before u call glReadPixels

glPixelStorei(GL_PACK_ALIGNMENT, 1);

since your data is not aligned to 32 bits.
See if this helps.

It works perfectly ^^

This morning I cheked that about glPixelStorei, and I tried options but my english is a bit poor and I couldn’t understand too well, so at the end I couln’t solve it.

If somebody has the same problem, I tried a few minutes ago insted of use GL_POINTS to draw it, do it using glDrawPixels (wich is like the “opposite” of glReadPixels) and it worked, though it wasn’t exactly what i wanted.

Thank you so much, really! you saved my brain from melting ^^