LWJGL Forum

Programming => General Java Game Development => Topic started by: Daslee on August 22, 2015, 12:24:16

Title: OpenGL and JavaFX
Post by: Daslee on August 22, 2015, 12:24:16
Hello. I'm trying to copy pixels from OpenGL to WritableImage, code looks good, at least for me.. But results are incorrect, here are image of how it looks (lwjgl window on left side, javafx on right side): http://s28.postimg.org/4h55qd1bx/Screenshot_from_2015_08_22_15_13_56.png (http://s28.postimg.org/4h55qd1bx/Screenshot_from_2015_08_22_15_13_56.png)

And that rectangle in JavaFX window moves to right, while triangle rotates inside LWJGL window. Result looks completely different than it should be.. This is the code that I use to copy pixels from OpenGL to WritableImage (via PixelWriter):
pixels.clear();
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, 640, 480, GL12.GL_BGRA, GL_UNSIGNED_BYTE, pixels);

pixelWriter.setPixels(0, 0, 640, 480, pixelWriter.getPixelFormat(), pixels, 0);


I tried printing pixelWriter.getPixelFormat(), and this is what I got:
Quotejavafx.scene.image.WritablePixelFormat$ByteBgraPre@721e34d8

So as I can see it uses byte type and bgra format, so I get pixels from OpenGL in the same way, but why result is incorrect?
Title: Re: OpenGL and JavaFX
Post by: spasi on August 22, 2015, 12:47:36
I think scanlineStride (last argument of setPixels) cannot be 0. Try 640 * 4.

For more ideas, see LWJGL-FX (https://github.com/Spasi/LWJGL-FX).
Title: Re: OpenGL and JavaFX
Post by: Daslee on August 22, 2015, 13:08:09
Quote from: spasi on August 22, 2015, 12:47:36
I think scanlineStride (last argument of setPixels) cannot be 0. Try 640 * 4.

For more ideas, see LWJGL-FX (https://github.com/Spasi/LWJGL-FX).

It works, thanks!