How do I add joystick support into OpenGL?
I want to add joystick support into an openGL application.
Is there开发者_运维百科 any class that can help me?
Thanks in advance.
OpenGL is a graphics API. It has no notion of input devices.
Need more info for a better answer such as platform. On Windows there are many options for handling input. Depending on what you want to do that is. Google for more info. But a start would be simple input handling via the Win32 API. This all presumes you use Windows of course.
OpenGL does not provide direct access to the joystick as it is only a graphics library.
For joystick support we will need to know what platform you are targeting.
For example, on Windows you would likely use DirectInput.
Some GLUT implementations have: glutJoystickFunc
As mentioned in other answers, OpenGL is only a graphics rendering API. It doesn't even know how to open a window, not to mention how to handle mouse or keyboard input; something else must do it for it.
If you want a cross-platform I/O wrapper for OpenGL which also provides joystick support, take a look at SDL - Simple DirectMedia Layer. It may scare you at first, but it's still easier than writing I/O and windowing stuff for a single platform, not to mention writing a wrapper for each platform out there (SDL covers many of them).
So, take a look at SDL.
精彩评论