Hey,
we are using SDL2 in our project for input only. Now, when I do not use SDL_SetRelativeMouseMode, the input works fine, but does not capture the mouse, which is very annoying for debugging in windowed mode.
So I tried setting SDL_SetRelativeMouseMode to true.
But that only leads to no input being captured at all, not even keyboard events any more! SDL_PollEvent simply never triggers in that case.
Here is how SDL is initialized:
Code:
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
Ogre::String error = SDL_GetError();
if (error != “”)
{
std::cout << "SDL_Init: " << error << std::endl;
error = “”;
}
SDL_SysWMinfo sysInfo;
SDL_VERSION(&sysInfo.version);
unsigned long hWnd=0;
window->getCustomAttribute(“WINDOW”, &hWnd);
SDL_Window* sdlWin = SDL_CreateWindowFrom((void*) hWnd); // The window is created by our graphics engine (Ogre)
error = SDL_GetError();
if (error != “”)
{
std::cout << "SDL_CreateWindowFrom: " << error << std::endl;
error = “”;
}
if(SDL_GetWindowWMInfo(sdlWin, &sysInfo) <= 0)
{
error = SDL_GetError();
if (error != “”)
{
std::cout << "SDL_GetWindowWMInfo: " << error << std::endl;
error = “”;
}
return false;
}
int result = SDL_SetRelativeMouseMode(SDL_TRUE);
error = SDL_GetError();
if (error != “”)
{
std::cout << "SDL_SetRelativeMouseMode: " << error << " " << result << std::endl;
error = “”;
}
I do get two errors here, one after SDL_CreateWindowFrom: "This operation is not supprted."
Not exactly a super helpful hint, if you ask me. “This doesn’t work”. Okaaay
Though I do not know if this is an actual problem, as input works just fine when not using relative mouse mode. And when I do not use SDL_CreateWindowFrom, no input works at all, so I think it is correct to use it like this.
Another error is reported after SDL_SetRelativeMouseMode. It is actually the same, “This operation is not supprted.”. I suspect it is just the last error repeated, and not really a new one, as the function returns 0 (would return -1 on error). Though I thought SDL_GetError() would flush the error.
I know I could reset the mouse position to the center of the screen each frame, thus simulating a captured mouse, but I would prefer not to.
So, what am I doing wrong here?
Btw. I am currently working on Windows and using MinGW, if that matters.