Mouse.getX/Y() and MacOS X

Started by Jny, June 27, 2007, 15:53:34

Previous topic - Next topic

Jny

Hi,

My name is Jny and I'm french. I'm making a game with LWJGL (http://www.elveyron.info/ It's in french, sorry).

The game runs perfectly under Windows and Linux.
But I got a problem with MacOS X ( 10.4.8 ): it seems the mouse pointer tracking doesn't work.

I do not grab the mouse and I use the Mouse.getX/Y() methods.
Under MacOS, Mouse.getX/Y() always return the initial mouse pointer coordinates (initial == when the game window appears on the screen)

Is there any protocol to follow under MacOS to make Mouse.getX/Y() work?

I call Display.update() at the end of my main loop and I check the mouse at the beginning (before the render). Is it a problem ?
Should I have to call Mouse.poll() before calling Mouse.getX/Y() ?
Should I need to empty the event buffer with a "while(Mouse.next());" before calling Mouse.getX/Y() ?
Should I have to call Mouse.create() manually ?

Thank you in advance for your answers.

PS : You, guys, made a very great work with LWJGL.


EDIT: The keyboard is not working either...

My main loop :
public void run() {
	while (! done) {
		if (Display.isCloseRequested()) { // Check for close requests
			switchMenu();
		} else {
			input();
			logic();
			render();
				
			Display.update();
				
			Timer.tick();
		}
	}
}


The input() method :
private void input() {
	// Toggle Menu
	if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && ! echap) {
		echap = true;
		switchMenu();
	}
	if (! Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
		echap = false;
	}		

        // ...

	int x = Mouse.getX();
	int y = Mouse.getY();

        // ...

}


If you want to test : http://www.elveyron.info/Clans-test1-MacOSX-20070626.zip

Jny

I have some news !

In my game, the user first arrive on a Swing window. He can check options and then launch the game (LWJGL Window creation).
When I launch the game directly (without the Swing launcher), the game runs perfectly under Mac OS X (mouse and keyboard are working).

So it seems that the Swing window "don't release" mouse and keyboard...  ???

Have you ever seen a problem like this ? Do you see an explanation ?

   // launching the game
   killSwingWindow();
   core.Application.launch(checkFullscreen.isSelected(), "XMP/test.xmp", "XGC/fast_game.xgc");


private void killSwingWindow() {
   setVisible(false);
   dispose();
}


elias

Hi,

I can reproduce the problem on my mac, however, we do something similar with one of our game where Mouse.getX()/Y() work fine. So can you please cut down your game to the bare minimum in order to reproduce the problem and then post the source? If possible, cut down the swing window to just a single "Run" button and your game window to just a black window printing out getX()/Y() whenever they change.

- elias

tof

Hello,

I'm the guy who's testing Jny's game on OS-X. I managed to borrow a MacBook from my job during the week-end in order to try to find a solution.

I hacked a simple launcher (I don't code in java) to launch a basic program (a black window printing the values of getX()/Y() in the title bar) Jny sent me to reproduce the problem. When pressing the button the test window is correctly created but both the launcher window and the test window don't receive the mouse events.

My test program: http://yumenokaze.free.fr/tmp/jny/TestTofXYbis.zip

Jny

Thanks tof for posting this test program.  ;)

With tof we made differents tests in order to find where the problem comes from but, for now, we don't succeed...

It seems we have a problem just because we are in a Swing window before creating the LWJGL context.

Is anyone have a LWJGL app with a launcher (with events handling working under Mac OS)?

elias

The problem is that you're hogging the AWT/Swing event thread, by never returning from the button' action listener:

ActionListener a = new ActionListener(){
		public void actionPerformed(ActionEvent e){
		    Application.main(new String[0]);
		}
	    };


since the action listener never returns, no more events will be processed and thus no events will reach your app. The reason this works on other platforms is that only Mac OS X rely on AWT events for Keyboard and Mouse.

To fix the problem, start the LWJGL processing (render()...display() loop) in a separate thread and let the action listener return.

BTW, good work on the test program even though it seems like it's not a LWJGL bug this time. It's short and clear while still demonstrating the problem.

- elias

Jny

It works !  :D

Thanks for this excellent explanation Elias. We can now understand why this event problem occurred only under Mac OS X.

Thank you very much, from Tof and me.

Jny