如何使用 SDL 从外部窗口收集输入?
我目前正在尝试在我的游戏引擎中重写 Ogre 和 SDL 之间的活页夹。最初我使用了 Ogre Wiki 此处中概述的方法。我最近将 SDL 版本更新到 1.3,并注意到“SDL_CreateWindowFrom()”函数调用并重新实现了我的活页夹允许Ogre构建窗口,然后从Ogre获取HWND并将其传递给SDL。
仅创建了一个窗口,我看到所有内容都正确呈现,但没有收集任何输入。我不知道为什么。这是我目前正在使用的代码(在 Windows 上):
OgreWindow = Ogre::Root::getSingleton().createRenderWindow(WindowCaption, Settings.RenderWidth, Settings.RenderHeight, Settings.Fullscreen, &Opts);
size_t Data = 0;
OgreWindow->getCustomAttribute("WINDOW",&Data);
SDLWindow = SDL_CreateWindowFrom(&Data);
SDL_SetWindowGrab(SDLWindow,SDL_TRUE);
我尝试环顾四周,有很多人已经在某种程度上取得了成功(例如 此处 或 此处)。但似乎没有人对实现这一点后处理输入发表评论。
我最初认为,也许由于 SDL 不拥有该窗口,因此默认情况下不会从中收集输入,这是合理的。所以我搜索了SDL API,只发现一个函数“SDL_SetWindowGrab()”似乎与输入捕获有关。但这样调用没有任何效果。
如何让 SDL 从 Ogre 制作的窗口收集输入?
I'm currently trying to re-write my binder between Ogre and SDL in my game engine. Originally I used the method outlined in the Ogre Wiki here. I recently updated my version of SDL to 1.3 and noticed the "SDL_CreateWindowFrom()" function call and re-implemented my binder to allow Ogre to build the window, and then get the HWND from Ogre to be passed into SDL.
Only one window is made and I see everything renders properly, however no input is collected. I have no idea why. Here's the code I am currently working with (on windows):
OgreWindow = Ogre::Root::getSingleton().createRenderWindow(WindowCaption, Settings.RenderWidth, Settings.RenderHeight, Settings.Fullscreen, &Opts);
size_t Data = 0;
OgreWindow->getCustomAttribute("WINDOW",&Data);
SDLWindow = SDL_CreateWindowFrom(&Data);
SDL_SetWindowGrab(SDLWindow,SDL_TRUE);
I've tried looking around and there are a number of people that have done this to one degree of success or another(such as here or here). But no one seems to comment on handling the input after implementing this.
I originally thought that maybe since SDL does not own the window it wouldn't collect input from it by default, which is reasonable. So I searched the SDL API and only found that one function "SDL_SetWindowGrab()" that seems to relate to input capture. But calling that has no effect.
How can I get SDL to collect input from my Ogre-made window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已经有一段时间了,但我想我应该为其他可能需要它的人提供答案。事实证明这是 SDL 1.3 中的一个错误/不完整的功能。 “CreateWindowFrom”方法最初并不打算专门用作输入处理程序。在撰写本文时,我自己和团队中的另一位成员为 Windows 和 Linux 编写了允许此用途运行的补丁,并将这些补丁提交给了 SDL。
It has been a while, but I figured I would put in the answer for others that may need it. It turned out to be a bug/incomplete feature in SDL 1.3. The "CreateWindowFrom" method wasn't originally intended to be used exclusively as an input handler. At the time of this writing I know myself and another on my team wrote patches for Windows and Linux that permitted this use to work and submitted those patches to SDL.