glReadPixels doesn't work in reshape(...) method

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

glReadPixels doesn't work in reshape(...) method

rhdxmr
my code is here


                        gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);
                        gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
                        ByteBuffer fbpixels = ByteBuffer.allocateDirect((WIDTH + 1)* (HEIGHT) * 3 - 1);
                        gl.glReadPixels(0,0, WIDTH, HEIGHT, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, this.fbpixels);
                        gl.glRasterPos3f(0,0,0);
                        gl.glDrawPixels(WIDTH, HEIGHT, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, this.fbpixels);

Q1.
why does not this code work in reshape(...) especially when called before glClear(GL.GL_COLOR_BUFFER_BIT); ? ==> fbpixels filled with only 0.
===> when called after glClear(GL.GL_COLOR_BUFFER_BIT), it filled with 255 (if glClearColor(1,1,1)).



But this code work well in display(...) method without glClear(GL.GL_COLOR_BUFFER_BIT);


Q2.
why glDrawPixels needs (WIDTH + 1)* (HEIGHT) * 3 - 1)?  
However glReadPixels only needs WIDTH * HEIGHT * 3