Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

is this working with glfw (opengl) window? #43

Open
SandSt0rm opened this issue Oct 9, 2017 · 8 comments
Open

is this working with glfw (opengl) window? #43

SandSt0rm opened this issue Oct 9, 2017 · 8 comments

Comments

@SandSt0rm
Copy link

i tried getting it to work, but the function "PeekMessage" is getting HWnd which is not GLFW window
is it possible combine two libraries together?

@RicoP
Copy link

RicoP commented Oct 9, 2017

I think you have to get the native window handle with glfwGetWin32Window. You must include glfw3native.h

@SandSt0rm
Copy link
Author

yeah thanks it worked!
great

@RicoP
Copy link

RicoP commented Oct 9, 2017

you are welcome. you can close this ticket i guess.

@X52p
Copy link

X52p commented Apr 3, 2018

I'm using GLFW to create a window and want to use gainput for keyboard and joystick events (on multiple platforms). It seems like GLFW is consuming the events and does not propagate them to gainput. Do I need to forward the events somhow.

@RicoP
Copy link

RicoP commented Apr 3, 2018

That is what I do


# if defined(_WIN32)
  {
    MSG msg;
    HWND hWnd = static_cast<HWND>(s_handle.native);
    while (PeekMessageW(&msg, hWnd, 0, 0, PM_REMOVE)) {
      TranslateMessage(&msg);
      //DispatchMessageW will trigger glfwResizeCallback so we don't have to call glfwPollEvents
      DispatchMessageW(&msg);

      // Forward any input messages to Gainput
      s_handle.p_inputManager->HandleMessage(msg);
    }
  }
# elif defined(__linux__)
  {
    XEvent event;
    while (XPending(static_cast<Display *>(s_handle.display))) {
      XNextEvent(static_cast<Display *>(s_handle.display), &event);
      s_handle.p_inputManager->HandleEvent(event);
    }
    glfwPollEvents();
  }
# elif defined(__EMSCRIPTEN__)
  {
    glfwPollEvents();
  }
# elif defined(__APPLE__)
#   error "implement me for iOS"
# else
#   error "unknown OS"
# endif

s_handle.p_inputManager is the gainput input manager

@X52p
Copy link

X52p commented Apr 4, 2018

where does s_handle.display and s_handle.native come from?

@RicoP
Copy link

RicoP commented Apr 6, 2018

inline void * getNativeDisplayType() {
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
    return glfwGetX11Display();
# elif BX_PLATFORM_OSX
    return nullptr;
# elif BX_PLATFORM_WINDOWS
    return nullptr;
# elif BX_PLATFORM_EMSCRIPTEN
    return nullptr;
# else
#   error "implement me"
# endif 
}

inline void * getNativeWindowHandle(GLFWwindow* window) {
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
    return (void*)(uintptr_t)glfwGetX11Window(window);
# elif BX_PLATFORM_OSX
    return glfwGetCocoaWindow(window);
# elif BX_PLATFORM_WINDOWS
  return glfwGetWin32Window(window);
# elif BX_PLATFORM_EMSCRIPTEN
  return nullptr;
# else
#   error "implement me"
# endif
}

  s_handle.native = getNativeDisplayType();
  s_handle.display = getNativeWindowHandle(window);

@skilled-solutions
Copy link

skilled-solutions commented Aug 3, 2018

I use the following approach:

XEvent event;
while (XPending(static_cast<Display *>(glfwGetX11Display()))) {
	XNextEvent(static_cast<Display *>(glfwGetX11Display()), &event);
	if (event.type<5&&event.type>1)
		manager.HandleEvent(event);
}
manager.Update();
glfwPollEvents();

But now my program is hanging and "Not responding". I think HandleEvent is consuming my Events. I tried also to filter the events but thats not enough. Maybe some advise from the creator himself?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants