LWJGL Forum

Programming => General Java Game Development => Topic started by: trBlueJ on November 28, 2019, 20:51:18

Title: GLFW Callbacks
Post by: trBlueJ on November 28, 2019, 20:51:18
Can someone please help me with callbacks in GLFW, they don't work as described on the GLFW website as it is in C and the starting up does not include how to define a function as the callback.
Title: Re: GLFW Callbacks
Post by: KaiHH on November 28, 2019, 21:33:28
The Get Started (https://www.lwjgl.org/guide) page on lwjgl.org contains an example with a GLFW callback (keycallback).
Title: Re: GLFW Callbacks
Post by: trBlueJ on November 29, 2019, 02:02:47
The Get Started (https://www.lwjgl.org/guide) page on lwjgl.org contains an example with a GLFW callback (keycallback).

Yes, however, I was wondering if there was a way to directly reference a function instead?
Title: Re: GLFW Callbacks
Post by: KaiHH on November 29, 2019, 07:51:17
Depends on what exactly you mean by "function" since in Java there is no such thing as a function. If you mean a "method" and by that you mean passing a reference to a Java method to a GLFW method expecting a callback interface type as a parameter, then you can simply use a Java Method Reference (since Java 8).
This is a standard feature in Java 8 and applies to all interface-typed receivers, such as method parameters or local methods variables.
Title: Re: GLFW Callbacks
Post by: trBlueJ on November 29, 2019, 11:37:33
Thank you.