husker-dev / openglfx

OpenGL implementation for JavaFX
Apache License 2.0
80 stars 10 forks source link

Replace OpenGLCanvas Runnable's to JavaFX styled Event #14

Closed orange451 closed 2 years ago

orange451 commented 2 years ago

JavaFX Node class commonly uses events like so:

public final void setOnMouseClicked( EventHandler<? super MouseEvent> value) {
    onMouseClickedProperty().set(value);
}

public final EventHandler<? super MouseEvent> getOnMouseClicked() {
    return (eventHandlerProperties == null) ? null : eventHandlerProperties.getOnMouseClicked();
}

It would be more in the spirit of JavaFX if OpenGLCanvas used a similar style for:

An example of this could be...

openGLCanvas.setOnRenderEvent((event)->{
    System.out.println(event.getFPS())
})
husker-dev commented 2 years ago

Names and meaning

The main reason why the methods are called that way and why there are so many of them is JOGL. Initially the project was based on it. And to make the transition from Swing/SWT JOGL smoother, I left the methods roughly the same. Default JOGL event listener includes:

GLAutoDrawable drawable that used to call GL functions, in my library (with lwjgl) is redudant So they transformes to:

Why onReshape/onRender

Also comes from JOGL, listeners may be more than one for each event. So, set***** will be incorrect.

P.S.

The library was planned simply as an add-on to JavaFX, which displays OpenGL separately. The goal was not to fully integrate with Property or Events

orange451 commented 2 years ago

I created a proof-of-concept that wraps around your OpenGLCanvas class. https://github.com/orange451/OpenGLFX-Ext/blob/master/src/main/java/com/huskerdev/openglfx/ext/OpenGLPane.java

Benefit to using JavaFX events, is I can easily pass in internal parameters. For example in the RenderEvent I can pass in the current timers delta time.

It also lets me have the OpenGLPane act as a layout manager by extending StackPane, so it can have its own children nodes.

husker-dev commented 2 years ago

I added Events. But not properties. You can test them.

husker-dev commented 2 years ago

I think at the moment the event syntax has come as close as possible to the example. Therefore, I will close the issue. If there are any questions, then you can reopen.