I am using GLUT for my windowing system to output some images onto the screen.
I also want to output the images to files. This has been a challenge. In some window resolution (such as 256×256, 1024×1024, 1920×1200), glReadPixels produce exact same image files as the screen. However when I resize the window (ex/ 655×652, 529×566 and do the screen capturing, images are zagged and seems like pixels have shifted linearly.
Any help will be appreciated!
EDIT – I am adding some code leading up to the glReadPixels call.
glGetIntegerv(GL_VIEWPORT, dimensions);
width = dimensions[2];
height = dimensions[3];
screencapture = (unsigned char*)malloc(width*height*sizeof(unsigned char));
glReadPixels(0,0,width, height, GL_GREEN, GL_UNSIGNED_BYTE, screencapture);
EDIT2 – I forgot to mention resizing the window with the mouse some times do produce good images. I guess it happens when I get the resolution just right.
The solution to your problem would be to either account for the extra bytes at the end of each line that is not a multiple of 4 wide (skipping over them), or to change
GL_PACK_ALIGNMENTto 1 (usingglPixelStore).(see my above comment)