Summary
I want to write the opengl pixels(GL_RGB) by glReadPixels to a QImage.This renders correct, but when i resize the window, it scales weird and distorts my shape(triangle).
What i tried
I tried (QImage)img.scale(width(),height(),Qt::KeepAspectRatio)
but it didn't solve the problem.
Played with how i write the pixels buffer from glReadPixels to QImage but No.Didn't work.
Should i read the pixels in three buffers(GLubyte *rpixel,*gpixel,*bpixel) or on one(GLubyte **pixels)?Which one is the easiest because i will resize the array when i will resize my window(so i want dynamic arrays).
Some code
I have uploaded a minimal code recreating the bug-weird behaviour in github.Download and compile using the Qt Creator. https://github.com/rivenblades/GlReadPixelsQT/tree/master
Pictures
Here is how i wanted(it works when not resizing)

Here is after resizing(Weird behaviour)

As you can see, when resizing, the image gets splitted at right and contunues at left at probably another row.So i am guessing the size of the image is wrong(needs more width?).
By default, the start of each row of an image is assumed to be aligned to 4 bytes. This is because the
GL_PACK_ALIGNMENTrespectivelyGL_UNPACK_ALIGNMENTparameter is by default 4, seeglPixelStore.When a framebuffer is read by
glReadPixelstheGL_PACK_ALIGNMENTparameter is considered.If you want to read the image in a tightly packed memory, with not alignment at the start of each line, then you've to change the
GL_PACK_ALIGNMENTparameter to 1, before reading the color plane of the framebuffer:If that is missed, this cause a shift effect at each line of the image, except if the length of a line of the image in bytes is divisible by 4.