View Full Version : Problem with glReadPixels and glCopyPixels

11-20-2008, 03:31 PM
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.


11-20-2008, 06:10 PM
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

11-20-2008, 07:50 PM
I see that you gave for glReadPixels negative values. After testing, it seem that at least the first 2 parameters of glReadPixels (http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml) must be in the range of the frame buffer size otherwise I get artifacts.

11-21-2008, 01:32 AM
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.


11-21-2008, 02:48 PM
You are right, my problem was all about these values.

Thanks lot.