I want users to be able to resize the game window. But when they do, I need to capture that event to re-init some stuff. Is there a way to respond to resizeing the window?
And is there something similar to respond to minimizing and maximizing it?
I want users to be able to resize the game window. But when they do, I need to capture that event to re-init some stuff. Is there a way to respond to resizeing the window?
And is there something similar to respond to minimizing and maximizing it?
LWJGL3:
First, get the Window handle from Application context:
final long windowHandle = ((LwjglDisplay)app.getContext()).getWindowHandle();
There is a method to register a “Window refresh callback”. It is called, when the window resize, but I don’t know, if this is the only case where it is called:
GLFW.glfwSetWindowRefreshCallback(windowHandle, new GLFWWindowRefreshCallbackI() {
@Override
public void invoke(final long arg0) {
System.err.println("Refreshed!");
}
});
Maybe compare the old vs. new size first:
final int widthTargetArray = new int[1];
...height
GLFW.glfwGetWindowSize(windowHandle, widthTargetArray, heightTargetArray);
Edit: There is also a glfwSetWindowSizeCallback/GLFWWindowSizeCallback, which is for sure the better way. ^^"
Or better yet, be agnostic about the underlying rendering system and just hook up to jmonkeyengine/jme3-core/src/main/java/com/jme3/system/SystemListener.java at master · jMonkeyEngine/jmonkeyengine · GitHub
Nice!
Any examples how to use this? Should I just implement it with the SimpleApplication offspring?
Yeah, looks like SimpleApplication implements this. So that would be one place you can hook your stuff to.
If you have already said this I was too lazy to read above comments. This is how I do it.
The LegacyApplication already implemented this so you can just override this method on the SimpleApplication. When resizing it will be fired.
@Override
public void reshape(int w, int h) {
System.out.println("Application requesting to reshape: " + w + ", " + h);
//This can only be called when the application has finished loaded all the screens etc.
super.reshape(w, h);
}