GLReadBufferUtil.readPixel changed orientation?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

GLReadBufferUtil.readPixel changed orientation?

Martin
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);

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

Thanks in advance for your suggestions.

Martin
Reply | Threaded
Open this post in threaded view
|

Re: GLReadBufferUtil.readPixel changed orientation?

Sven Gothel
Administrator
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
Reply | Threaded
Open this post in threaded view
|

Re: GLReadBufferUtil.readPixel changed orientation?

Martin
Recently = yesterday evening :)

I still don't understand as the caller code did not changed since at least september 2013 and was working properly.

Thanks for mentioning AWTGLReadBufferUtil, it will be very usefull in jzy3d.

Martin

Reply | Threaded
Open this post in threaded view
|

Re: GLReadBufferUtil.readPixel changed orientation?

Sven Gothel
Administrator
On 10/16/2014 10:46 AM, Martin [via jogamp] wrote:
> Recently = yesterday evening :)
>
> I still don't understand as the caller code did not changed since at least
> september 2013 and was working properly.

And I doubt we changed anything regarding vertical flipping here.

Maybe some sideeffect of the GLDrawable vertical orientation ?
But this is just a wild guess ..

>
> Thanks for mentioning AWTGLReadBufferUtil, it will be very usefull in jzy3d.

You are very welcome.

You may also look at GLJPanel's OffscreenBackend,
which uses quite some nice 'hacks' to utilize
one BufferedImage in native PixelFormat etc etc

~Sven

>
> Martin


signature.asc (828 bytes) Download Attachment