LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: idhan on February 25, 2015, 16:08:06

Title: [Solved] example for glfwSetWindowSizeCallback
Post by: idhan on February 25, 2015, 16:08:06
Hi,

I'm comming from the c++ 3D world, so I'm pretty new in Java and specially in LWJGL 3.
I'm trying to update my GL_MODELVIEW matrix after my window has been resized,
but I can't find any full example of how to use glfwSetWindowSizeCallback in LWJGL 3.

Any ideas where I can find a full example for this kind of callbacks?

thanks in advance! :-)
Title: Re: example for glfwSetWindowSizeCallback
Post by: Neoptolemus on February 25, 2015, 16:45:35
So when you create a new GLFWWindow object using glfwCreateWindow, the method returns a long which is the ID for that window. This long is what you supply to glfwSetWindowSizeCallback for the first parameter, as a replacement for the GLFWwindow pointer you supplied in the original C library.

You then need to to have created a GLFWWindowSizeCallback object which is invoked using a long (again, the long supplied when you created the window) and the height and width parameters, and supply that to glfwSetWindowSizeCallback as the second parameter.

So pseudo code would look like this:


long myWindow = glfwCreateWindow(800, 600, "My Window", NULL, NULL);

GLFWWindowSizeCallback mySizeCallback = new GLFWWindowSizeCallback();
mySizeCallback.invoke(myWindow, 640, 480);

glfwSetWindowSizeCallback(myWindow, mySizeCallback);



I hope that's right!
Title: Re: example for glfwSetWindowSizeCallback
Post by: SHC on February 25, 2015, 17:19:04
Since you are coming from the C++ world, using the lambdas will help you actually.


// The callback function is this.
private void windowSizeCallback(long window, int width, int height)
{
    // Do anything here.
}

And now to set the code, we use the lambdas like this.


// This is an example of method references in Java 8
GLFWWindowSizeCallback callback = GLFWWindowSizeCallback(this::windowSizeCallback);

// Now set the callback
glfwSetWindowSizeCallback(myWindow, callback);

Finally before destroying the window, you have to release the callbacks.


callback.release();

And that's all there is to it. You won't invoke the callback manually, it's invoked my GLFW.
Title: Re: example for glfwSetWindowSizeCallback
Post by: idhan on March 03, 2015, 14:30:49
Thanks you Neoptolemus and SHC.. it work like a charm.

days ago I tried to reply to say thank you, but can't post anything using firefox/opera from linux. Every time I try to replay something after I press "post" the connection is lost... no idea why.. (I'm trying this time from windows as the first time)

Is someone here with linux responding on this forum?

any way.. thank you!