Hello Guest

[Solved] example for glfwSetWindowSizeCallback

  • 3 Replies
  • 5292 Views
[Solved] example for glfwSetWindowSizeCallback
« 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! :-)
« Last Edit: March 05, 2015, 09:20:51 by idhan »

Re: example for glfwSetWindowSizeCallback
« Reply #1 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:

Code: [Select]
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!
« Last Edit: February 25, 2015, 16:49:34 by Neoptolemus »

*

Offline SHC

  • **
  • 94
    • GoHarsha.com
Re: example for glfwSetWindowSizeCallback
« Reply #2 on: February 25, 2015, 17:19:04 »
Since you are coming from the C++ world, using the lambdas will help you actually.

Code: [Select]
// 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.

Code: [Select]
// 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.

Code: [Select]
callback.release();
And that's all there is to it. You won't invoke the callback manually, it's invoked my GLFW.

Re: example for glfwSetWindowSizeCallback
« Reply #3 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!