Problem with glReadPixels and glCopyPixels

Hi. I´m trying to create some examples of glReadPixels and glCopyPixels but I´m having some problems.
After rendering a scene I use glReadPixels to read a section of the screen and then I pass that pointer to glDrawPixels so I can draw it in a new rastre location. The thing is that it only draws a black square with two gray lines. Also glCopyPixels does´t draw any thing when I try to use it.
I don´t know if it is some driver problem or what am I doing wrong.

Here are the functions:

void Read(void)
int w = 127;
int h = 85;

GLubyte* pixels = new GLubyte[w * h * 3]);

glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(-5, -5, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);

glRasterPos2i(0, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glDrawPixels(w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);

delete[] pixels;

void Copy(void)
glRasterPos2i(5, 5);
glCopyPixels(-5, -5, 127, 85, GL_COLOR);

Please help.


I also have problem with glReadPixels() and glDrawPixels() - nothing happens even after a bunch of disable : GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_FOG, GL_LIGHTING, GL_DITHER, GL.GL_BLEND

I see that you gave for glReadPixels negative values. After testing, it seem that at least the first 2 parameters of glReadPixels must be in the range of the frame buffer size otherwise I get artifacts.

oumind: I also have problem with glReadPixels() and glDrawPixels() …

if you have problems with a function, why not reading the documentation on it first? f.e. glDrawPixels requires a raster position to be set before drawing any pixels. If not done you won’t see anything in the worst case. Now this is something you can read in the documentation.

You are right, my problem was all about these values.

Thanks lot.