[Patch] Allow LWJGL Display resizable

Well playinga round with the swing stuff, I notices poor performance in large resolutions, but I really liked the ability to resize windows with dragging so I searched for alternatives.

In fact in lwjgl this feature was added for the native display, so I made it work with jme3.

In LWJGLDisplay replace:

	@Override
	public void runLoop() {
		//detect lwjgl display size changes
		if (Display.wasResized()) {
			//keep settings in sync with the actual Display
			this.settings.setWidth(Display.getWidth());
			this.settings.setHeight(Display.getHeight());
			this.listener.reshape(this.settings.getWidth(), this.settings.getHeight());
		}
		// This method is overriden to do restart
		if (this.needRestart.getAndSet(false)) {
			try {
				this.createContext(this.settings);
			} catch (final LWJGLException ex) {
				LwjglDisplay.logger.log(Level.SEVERE, "Failed to set display settings!", ex);
			}
			this.listener.reshape(this.settings.getWidth(), this.settings.getHeight());
			LwjglDisplay.logger.fine("Display restarted.");
		}

		super.runLoop();
	}

Now resizing can be enabled using Display.setResizable(true) and seems to behave correctly. (maybee make this the default as well, to unify behaviour with the swing panel.

4 Likes

Unadressed issue here is that there’s no notification of a settings change. I.e. if the application wants to persist the settings, it won’t get triggered to do that.
That’s more a problem of AppSettings than of LWJGLDisplay though.

Is a restart needed? My code works fine with reshape().
Also, I’m setting a minimum size of 1 for width and height.

I’m just doing this in MyApplication.update():

[java] if (Display.wasResized()) {
int newWidth = Math.max(Display.getWidth(), 1);
int newHeight = Math.max(Display.getHeight(), 1);
reshape(newWidth, newHeight);
}[/java]

Am I missing anything there?

The other stuff was already there, I just added that resizeable detection stuff.

@Empire Phoenix said: The other stuff was already there, I just added that resizeable detection stuff.

Then why not use a simple diff instead of plopping code? I don’t call this a patch even though it’s a good idea.

Well i would if I could, but I have to delete the svn stuff as it collides with my git

@Empire Phoenix said: Well i would if I could, but I have to delete the svn stuff as it collides with my git

Understandable as I know you’ve modified the engine pretty heavily, but a bit more details on what was changed would have made things a lot easier for everyone. :slight_smile: Also the use of the JAVA tag and not the generic CODE tag… :wink:

Actuall I’m quite near to the standart jme, as since I use a es jme is no longer a central part of my stuff, I could get rid of most changes.
Also some of my changes are already back in the engine, (eg the meshshape save stuff)

@Empire Phoenix said: The other stuff was already there, I just added that resizeable detection stuff.

So lines 3-9 are new?
(Post a diff dammit…)

Well I can post a pseudo diff:

[java]
@Override
public void runLoop() {

  • //detect lwjgl display size changes
  • if (Display.wasResized()) {
  •  //keep settings in sync with the actual Display
    
  •  this.settings.setWidth(Display.getWidth());
    
  •  this.settings.setHeight(Display.getHeight());
    
  •  this.listener.reshape(this.settings.getWidth(), this.settings.getHeight());
    
  • }
    // This method is overriden to do restart
    if (this.needRestart.getAndSet(false)) {
    try {
    this.createContext(this.settings);
    } catch (final LWJGLException ex) {
    LwjglDisplay.logger.log(Level.SEVERE, “Failed to set display settings!”, ex);
    }
    this.listener.reshape(this.settings.getWidth(), this.settings.getHeight());
    LwjglDisplay.logger.fine(“Display restarted.”);
    }
super.runLoop();

}
[/java]

:slight_smile:

I’m not 100% sure why I make sure that the size is at least 1x1. I think something in LWJGL crashed at that size - you could try resizing your window to zero width or height and see what happens.

If the only difference in code is those lines I don’t think it would make a difference as afaik (on windows at least) the main window isn’t resizable and is fixed to the resolution used in the AppSettings.

You need to call Display.setResizable(true); This was always the case it was just not resizing the camera inside a window without the above change

@madjack said: If the only difference in code is those lines I don't think it would make a difference as afaik (on windows at least) the main window isn't resizable and is fixed to the resolution used in the AppSettings.

This works on windows, in some lwjgl version after jme3 started, they added this, this just makes it useable, as a resizable windows is only usfull if the content resizes as well.

At least on linux I cannot get it to crash with small sizes.

I just dumped the lines above into the class, rebuilt everything and it’s the same way it was before. I can’t resize the window and the maximize button is greyed out.

There’s got to be something missing.

I’m using the latest jME from google code.

You enabled it with Display.setResizable(true); ?

@Empire Phoenix said: You enabled it with Display.setResizable(true); ?

Nope. That’s what I said in a previous post “if it’s only the code above it won’t make a difference”. That method isn’t called. I’ll try that.

Yep, that made it work.

There was some slight issues, but nothing major. Looks like vertical stretching even after the proper ratio was restored (while the game was running), but that might be issues from my side since the game isn’t made to be resized on the fly like that.