LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: dlubarov on December 28, 2013, 01:52:25

Title: How to move LWJGL's window after it has been created?
Post by: dlubarov on December 28, 2013, 01:52:25
I tried calling Display.setLocation, but it doesn't seem to work if the display has already been created. I'm not sure if this is a bug or just the expected behavior of setLocation.

Here's an example to demonstrate. I want the window to move up and down in response to the keyboard. When I run it, it prints "moving up/down", but the window doesn't move.


public class Test {
  public static void main(String[] args) throws Exception {
    Display.setDisplayMode(new DisplayMode(640, 480));
    Display.create();
   
    while (!Display.isCloseRequested()) {
      if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
        System.out.println("moving up");
        Display.setLocation(Display.getX(), Display.getY() - 1);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
        System.out.println("moving down");
        Display.setLocation(Display.getX(), Display.getY() + 1);
      }
      Display.update();
      Display.sync(60);
    }
  }
}


I can get it to work by destroying and recreating the display with each setLocation, but I want to move the window in small increments, so it's not a practical solution.

I'm using LWJGL 2.9.1 on OSX.

(I also made a question (http://"http://stackoverflow.com/questions/20797514/how-to-move-lwjgls-window-after-it-has-been-created") on StackOverflow yesterday. I'll be checking both.)

Thanks,
Daniel
Title: Re: How to move LWJGL's window after it has been created?
Post by: Cornix on December 28, 2013, 11:15:22
Display.setLocation works for me like a charm. Even after creating the window. (testing on windows 7)
Are you sure, that its Display.setLocation that doesn work? Maybe its your Conditions.
Title: Re: How to move LWJGL's window after it has been created?
Post by: ra4king on December 28, 2013, 11:51:51
Your code snippet works here. Windows 8 64bit.
Title: Re: How to move LWJGL's window after it has been created?
Post by: dlubarov on December 29, 2013, 09:39:25
Thank you both for testing it. I tried some different versions, and it works on my machine (OSX 10.9) if I use 2.8.5, but not 2.9.0. I'll post a bug report.
Title: Re: How to move LWJGL's window after it has been created?
Post by: ra4king on December 29, 2013, 21:41:06
Thanks for filing the bug report!