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 256x256, 1024x1024, 1920x1200), glReadPixels produce exact same image files as the scree开发者_Python百科n. However when I resize the window (ex/ 655x652, 529x566 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_ALIGNMENT
to 1 (using glPixelStore
).
(see my above comment)
精彩评论