Hello Guest

glfwSetInputMode = game freeze !

  • 8 Replies
  • 5830 Views
*

Offline Yuri6037

  • ***
  • 104
  • Check out our website : http://www.sldt-team.net !
    • SLDT
glfwSetInputMode = game freeze !
« on: July 11, 2015, 15:04:51 »
Hello all,

So I found out that by removing those two lines of codes : "glfwSetInputMode(gameWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);" and "glfwSetInputMode(gameWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);", I can remove lag spites happening randomly.

So can you explain why those calls creates random lag spites ? This wasn't the case in the old LWJGL library.

I'm using those functions in the main rendering loop.

After I have a problem with some code in my engine :
- How can I get the current pressed key on the keyboard ?
- How can I get the position of the mouse wheel ?
- How can I get the button number of my mouse in GLFW ?
- How can I lock the cursor in the window itself ? I can hide it, but it can still leave the window, I want it to never be able to leave the window, how to do that ?
- How can I switch on/off fullscreen like on the old LWJGL with Display.setFullscreen ?

Oh and by the way, the new LWJGL allows more things, but still needs much work and maybe you should add an option to not include the part of the little library, because for some guys the library is useless (like me)...

And again please excuse me for images not working on signature/profile. We're having some .htaccess problems with our host (www.sldt-team.net)

Thanks by advance,
Yuri.
« Last Edit: July 11, 2015, 15:27:36 by Yuri6037 »

*

Offline spasi

  • *****
  • 2212
    • WebHotelier
Re: glfwSetInputMode = game freeze !
« Reply #1 on: July 11, 2015, 15:16:45 »
So I found out that by removing those two lines of codes : "glfwSetInputMode(gameWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);" and "glfwSetInputMode(gameWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);", I can remove lag spites happening randomly.

So can you explain why those calls creates random lag spites ? This wasn't the case in the old LWJGL library.

I'm using those functions in the main rendering loop.

Please post a code sample that reproduces the issue. The above description does not make much sense, I don't know why you would call these functions in your rendering loop.

After I have a problem with some code in my engine :
- How can I get the current pressed key on the keyboard ?
- How can I get the position of the mouse wheel ?
- How can I get the button number of my mouse in GLFW ?
- How can I lock the cursor in the window itself ? I can hide it, but it can still leave the window, I want it to never be able to leave the window, how to do that ?
- How can I switch on/off fullscreen like on the old LWJGL with Display.setFullscreen ?

Everything you need to know is in the GLFW documentation. The event callbacks are a bit different in Java, see the Events demo.

Toggling in and out of fullscreen, without losing the OpenGL context, is currently a pending issue with GLFW. Currently, if you'd like to avoid having to reload resources (textures, models, etc) you can use context sharing.

Oh and by the way, the new LWJGL allows more things, but still needs much work and maybe you should add an option to not include the part of the little library, because for some guys the library is useless (like me)...

Are you talking about stb?

*

Offline Yuri6037

  • ***
  • 104
  • Check out our website : http://www.sldt-team.net !
    • SLDT
Re: glfwSetInputMode = game freeze !
« Reply #2 on: July 11, 2015, 15:25:37 »
So I found that I can delete the package stb (which is completely useless for me) without LWJGL to crash. But I'd prefer to have it in an external jar it's better.

For the code well the main game rendering loop is about 100 lines of codes and takes place... I don't know much about GLFW but maybe the function to hide the cursor is not designed to be ran in loop. I'll try to use the function only when boolean changes not everytime.

Thanks for your help however I did not find any way in the GLFW doc to lock the mouse cursor inside the winow like old LWJGL could do.
And I can't find any way to get mouse button count and to know when user press which key on keyboard. That means no ways for TextField/PasswordField/ChatField to work. I can no longer save levels while being in game...

*

Offline spasi

  • *****
  • 2212
    • WebHotelier
Re: glfwSetInputMode = game freeze !
« Reply #3 on: July 11, 2015, 15:42:21 »
Thanks for your help however I did not find any way in the GLFW doc to lock the mouse cursor inside the winow like old LWJGL could do.

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED) is equivalent to grabbing the mouse in LWJGL 2.

And I can't find any way to get mouse button count and to know when user press which key on keyboard. That means no ways for TextField/PasswordField/ChatField to work. I can no longer save levels while being in game...

For mouse clicks you use the glfwSetMouseButtonCallback. For keyboard input, you can use glfwSetKeyCallback (for controls) or glfwSetCharCallback (for unicode text input).

*

Offline Yuri6037

  • ***
  • 104
  • Check out our website : http://www.sldt-team.net !
    • SLDT
Re: glfwSetInputMode = game freeze !
« Reply #4 on: July 11, 2015, 15:57:50 »
GLFW_CURSOR_DISABLED is not working, it does not block the cursor from going outside the window bounds and seconds blocks you from closing the application via the red box on Windows.

Thanks for your help about callbacks. I think the input system for SLDT's GameEngine on LWJGL 3 will be hugeley more complicated because well I'll need to use my own Enum for keys due to the fact It's more quick to type KEY_SOMETHING instead of GLFW_KEY_SOMETHING. I'll need to make a switch with every cases of every characters on the keyboard (let's think about 1 day to type everything...).

So I fixed the freeze issue by removing those 2 functions from rendering loop. I put an if block to get when the boolean showCursor changes and if the game uses it's own cursor drawing, then I simply hide one time only at game startup.

So with your help, I think I can use the callback method for onKeyTyped but If I want to know which key is currently down how can I do ?

EDIT : setKeyCallBack does not do addKeycallback, well it's a problem. If the game can only has one Input for everything... Then the Scene system is to remove because it's not static. I'll try using another library. The setKeyCallback is not for me.
« Last Edit: July 11, 2015, 16:03:36 by Yuri6037 »

*

Offline spasi

  • *****
  • 2212
    • WebHotelier
Re: glfwSetInputMode = game freeze !
« Reply #5 on: July 11, 2015, 16:42:21 »
GLFW_CURSOR_DISABLED is not working, it does not block the cursor from going outside the window bounds and seconds blocks you from closing the application via the red box on Windows.

For me it works exactly like Mouse.setGrabbed(true) in LWJGL 2. If you're sure there's a bug, please post a code sample and info about your system.

Thanks for your help about callbacks. I think the input system for SLDT's GameEngine on LWJGL 3 will be hugeley more complicated because well I'll need to use my own Enum for keys due to the fact It's more quick to type KEY_SOMETHING instead of GLFW_KEY_SOMETHING. I'll need to make a switch with every cases of every characters on the keyboard (let's think about 1 day to type everything...).

So I fixed the freeze issue by removing those 2 functions from rendering loop. I put an if block to get when the boolean showCursor changes and if the game uses it's own cursor drawing, then I simply hide one time only at game startup.

So with your help, I think I can use the callback method for onKeyTyped but If I want to know which key is currently down how can I do ?

EDIT : setKeyCallBack does not do addKeycallback, well it's a problem. If the game can only has one Input for everything... Then the Scene system is to remove because it's not static. I'll try using another library. The setKeyCallback is not for me.

LWJGL 3 and GLFW are low-level libraries. They provide low-level functionality, but you can build high-level APIs on top of that. The callbacks give you access to the raw events. If you want, you could use these events to update a custom data structure that provides the functionality you need; querying if a key is currently down, notifying multiple listeners, etc.

*

Offline Yuri6037

  • ***
  • 104
  • Check out our website : http://www.sldt-team.net !
    • SLDT
Re: glfwSetInputMode = game freeze !
« Reply #6 on: July 12, 2015, 04:09:31 »
Thanks for your info.

About cursor disabled problem, well that's simple, it works but not exactly like the one in LWJGL 2.

It disappears completely, but it can still go out of the window unlike LWJGL 2. And second when you hit Windows key then click the window to drag, or any box, it makes the window crazy and leaves it inside the task bar, then you can say hello process killer...

About the key callback, is the there any way to get the current key down ?

*

Offline spasi

  • *****
  • 2212
    • WebHotelier
Re: glfwSetInputMode = game freeze !
« Reply #7 on: July 12, 2015, 11:39:35 »
About cursor disabled problem, well that's simple, it works but not exactly like the one in LWJGL 2.

It disappears completely, but it can still go out of the window unlike LWJGL 2. And second when you hit Windows key then click the window to drag, or any box, it makes the window crazy and leaves it inside the task bar, then you can say hello process killer...

Honestly, it sounds like you're doing something wrong. Please post some code and info about your system, I can't help you otherwise.

About the key callback, is the there any way to get the current key down ?

I'm not sure what you're asking. The key callback is fired on every key press and release, and also fire repeat events while holding down a key. The callback parameters provide all the information you need.

*

Offline SilverTiger

  • *
  • 18
  • がんばってください!
    • SilverTiger Development
Re: glfwSetInputMode = game freeze !
« Reply #8 on: July 12, 2015, 20:04:39 »
Alternatively to the callback you could also use glfwGetKey(window, key) which will give you GLFW_PRESS if the key is pressed or GLFW_RELEASE if the key is not pressed.
More details on handling input can be found here, here and here.

I made a tutorial some time ago for getting started with LWJGL3, you may want to take a look at it here.
More tutorials on LWJGL3 can be found in the LWJGL3-Wiki.
Hope that helps.