Question

Here's my code

#include <SDL.h>
#include <iostream>

int main(int argc,char **argv)
{
    std::cout<<SDL_NumHaptics()<<std::endl<<SDL_NumJoysticks()<<std::endl;
    return 0;
}

When I run it it says 0 joysticks and 0 haptic devices, this happens on both linux and windows. On linux I have xboxdrv installed and it detects the controller and on windows I also have the necessary drivers installed. SFML does detect the controller as a joystick on linux, however, I would much rather use SDL, due to its support for haptic devices and openGL profiles.

Was it helpful?

Solution

You forgot to initialize SDL. For example:

SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC);

Or, if you're using SDL for everything (graphics, audio, etc.) then:

SDL_Init(SDL_INIT_EVERYTHING);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top