OpenGL and JavaFX

Started by Daslee, August 22, 2015, 12:24:16

Previous topic - Next topic

Daslee

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

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?

spasi

I think scanlineStride (last argument of setPixels) cannot be 0. Try 640 * 4.

For more ideas, see LWJGL-FX.

Daslee

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.

It works, thanks!