Sign in to follow this  

glReadPixels help

Recommended Posts

Hi, I'm trying to build some examples of glReadPixels. But my problem is that I cant't read anything. When I call the function to read from the screen and then try to paint the content again with glDrawPixels (giving glDrawPixels the pointer in which glReadPixels stored the data) in another raster position, I just get a black with gray stripes square. Are there some settings we need to use with this function? I get the same results with glCopyPixels it just don't draw (copy) anything. Can someone help me please? Thanks.

Share this post

Link to post
Share on other sites
This is the function I was trying. After reading in "pixels" with glReadPixels I send the pointer to glDrawPixels expecting to get the image draw in the new location, but I just get a black and gray square.

void function(void)
int width = 127;
int height = 85;

unsigned char* pixels = new unsigned char[width*height*3];

glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(-5, -5, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);

glRasterPos2i(5, 5);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);

delete[] pixels;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this