使用 SDL_INIT_JOYSTICK 而不使用 SDL_INIT_VIDEO
我在尝试使用 SDL 为我的应用程序获取操纵杆支持方面花费了一些时间,主要是因为初始化步骤如下:
SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_VIDEO);
SDL_JoystickEventState(SDL_ENABLE);
如果我只是初始化操纵杆,则它不起作用,它需要与视频一起完成。我希望它非常简约,所以很高兴知道是否有一种方法可以仅初始化操纵杆。如果没有,有人可以告诉我初始化视频而不使用它是否有什么缺点?
我这里使用的是 Ubuntu,但我希望它可以在各种平台上运行。这种行为在不同的环境中是否有所不同?
谢谢 :)
I've lost some time trying to get joystick support for my an application using SDL, mostly because the initialization steps where these:
SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_VIDEO);
SDL_JoystickEventState(SDL_ENABLE);
It didn't work if I just initialized the joystick, it needed to be done together with the video. I want this to be very minimalistic, so it would be nice to know if there's a way to initialize just the joystick. If not, can someone tell me if there's any disadvantage of initializing the video and never using it?
I'm on Ubuntu here, but I expect this to run in various platforms. Does this behavior vary in different environments?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在开发一个采用手柄输入的小型 CLI 应用程序时,我遇到了类似的问题。基本上,如果没有 SDL_INIT_VIDEO,它就无法工作,因为 SDL 事件系统源于视频驱动程序,至少在 Linux (X11) 上是这样。
在不创建窗口的情况下初始化视频是完全可以的(至少它可以工作)。我已经在 Win32 和 Linux 上测试了这种方法,因此它似乎在多平台上也能正常工作。
I had similiar issues when developing a small CLI app that took joypad input. Basically, it didn't work without SDL_INIT_VIDEO because SDLs event system stems from the video driver, at least on Linux (X11).
It is perfectly fine to init video without ever creating a window (it works at least). I've tested this approach on both Win32 and Linux, so it does seem to work fine multiplatform as well.
我有一个类似的问题,我通过不使用事件循环解决了它。相反,我手动更新操纵杆,然后使用 SDL 函数检查操纵杆。
I have a similar issue, I solved it by not using the event loop. Instead I manually update the joysticks and then use the SDL functions to check the joysticks.