Hello Guest

OpenGL and JavaFX

  • 2 Replies
  • 10137 Views
*

Offline Daslee

  • ***
  • 126
OpenGL and JavaFX
« 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

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):
Code: [Select]
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:
Quote
javafx.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?

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: OpenGL and JavaFX
« Reply #1 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.

*

Offline Daslee

  • ***
  • 126
Re: OpenGL and JavaFX
« Reply #2 on: August 22, 2015, 13:08:09 »
I think scanlineStride (last argument of setPixels) cannot be 0. Try 640 * 4.

For more ideas, see LWJGL-FX.

It works, thanks!