Re: GLReadBufferUtil.readPixel changed orientation?

Posted by Sven Gothel on
URL: https://forum.jogamp.org/GLReadBufferUtil-readPixel-changed-orientation-tp4033366p4033369.html

On 10/15/2014 10:14 PM, Martin [via jogamp] wrote:

> Hi,
>
> In Jzy3d, I used to to create screenshots as follow :
>
> GLReadBufferUtil screenshot = new GLReadBufferUtil(false, false);
> screenshot.readPixels(gl, true);
>
> And it has been working for years :)
>
> I recently noticed that the screenshot is serialized up-side-down so I wonder
> if I should switch to a definitive
> screenshot.readPixels(gl, false);
It is all in OpenGL orientation, so is the produced texture.
Our PNG writer (default w/ TextureIO) takes this into consideration
and properly flips the vertical orientation.

Dunno what you mean w/ 'recently', since GLReadBufferUtil was always behaving
like this.

>
> or if I should consider some more subtle reason to say true or false before
> reading pixels.

it is all in the API doc and source code ..

GLReadBufferUtil:

    /**
     * @param alpha true for RGBA readPixels, otherwise RGB readPixels. Disclaimer: Alpha maybe forced on ES platforms!
     * @param write2Texture true if readPixel's TextureData shall be written to a 2d Texture
     */
    public GLReadBufferUtil(final boolean alpha, final boolean write2Texture) { ..}

    /**
     * Read the drawable's pixels to TextureData and Texture, if requested at construction.
     *
     * @param gl the current GL context object. It's read drawable is being used as the pixel source.
     * @param mustFlipVertically indicates whether to flip the data vertically or not.
     *                           The context's drawable {@link GLDrawable#isGLOriented()} state
     *                           is taken into account.
     *                           Vertical flipping is propagated to TextureData
     *                           and handled in a efficient manner there (TextureCoordinates and TextureIO writer).
     *
     * @see #GLReadBufferUtil(boolean, boolean)
     */
    public boolean readPixels(final GL gl, final boolean mustFlipVertically) { .. }

>
> Thanks in advance for your suggestions.

        if(readBufferUtil.readPixels(gl, false)) {
            readBufferUtil.write(new File("lala.png"));
        }

If you like to use AWT and/or a buffered image,
mustFlipVertically is usually 'true' as used via specialization  AWTGLReadBufferUtil.

See unit test: com.jogamp.opengl.test.junit.jogl.acore.TestGLOffscreenAutoDrawableBug1044AWT

~Sven



signature.asc (828 bytes) Download Attachment