Incorrectly read and write pixels using opengl