PDA

View Full Version : Problem with glReadPixels and glCopyPixels



EMBT30
11-20-2008, 04:31 PM
Hi. Im trying to create some examples of glReadPixels and glCopyPixels but Im 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 doest draw any thing when I try to use it.
I dont 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.

Thanks.

oumind
11-20-2008, 07: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

trinitrotoluene
11-20-2008, 08: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.

_NK47
11-21-2008, 02: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.

http://opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/readpixels.html
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/drawpixels.html

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

Thanks lot.