int main(int argc, char *argv[]) { const char *name; int i; int nController = 0; SDL_GameController *gamecontroller; SDL_SetHint( SDL_HINT_GAMECONTROLLERCONFIG, "341a3608000000000000504944564944,Aferglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" ); /* Initialize SDL (Note: video is required to start event loop) */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } /* Print information about the controller */ for (i = 0; i < SDL_NumJoysticks(); ++i) { if ( SDL_IsGameController(i) ) { nController++; name = SDL_GameControllerNameForIndex(i); printf("Game Controller %d: %s\n", i, name ? name : "Unknown Controller"); } } printf("There are %d game controllers attached\n", nController); if (argv[1]) { int nreportederror = 0; SDL_Event event; gamecontroller = SDL_GameControllerOpen(atoi(argv[1])); while ( s_ForceQuit == SDL_FALSE ) { if (gamecontroller == NULL) { if ( nreportederror == 0 ) { printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError()); nreportederror = 1; } } else { nreportederror = 0; WatchGameController(gamecontroller); SDL_GameControllerClose(gamecontroller); } gamecontroller = NULL; SDL_WaitEvent( &event ); if ( event.type == SDL_JOYDEVICEADDED ) gamecontroller = SDL_GameControllerOpen(atoi(argv[1])); } } SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ); return (0); }
void refresh_controllers() { for (s32 i = 0; i < MAX_GAMEPADS; i++) { if (haptics[i]) { SDL_HapticClose(haptics[i]); haptics[i] = nullptr; } if (controllers[i]) { SDL_GameControllerClose(controllers[i]); controllers[i] = nullptr; } } for (s32 i = 0; i < SDL_NumJoysticks(); i++) { if (SDL_IsGameController(i)) { controllers[i] = SDL_GameControllerOpen(i); SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controllers[i]); if (SDL_JoystickIsHaptic(joystick)) { haptics[i] = SDL_HapticOpenFromJoystick(joystick); if (SDL_HapticRumbleInit(haptics[i])) // failed { SDL_HapticClose(haptics[i]); haptics[i] = nullptr; } } } } }
bool GameController::open(int c) { if (sdl_device) { close(); } if (c < 0 || c >= SDL_NumJoysticks()) { return false; } if (!SDL_IsGameController(c)) { return false; } sdl_device = SDL_GameControllerOpen(c); if (sdl_device == nullptr) { printlog("Error: Failed to open game controller! SDL Error: %s\n", SDL_GetError()); } else { id = c; printlog("Successfully initialized game controller!\n"); name = (SDL_GameControllerNameForIndex(c)); printlog("Controller name is \"%s\"", name.c_str()); } return (sdl_device != nullptr); }
JoystickScriptingInterface::JoystickScriptingInterface() : #ifdef HAVE_SDL2 _openJoysticks(), #endif _isInitialized(false) { #ifdef HAVE_SDL2 bool initSuccess = (SDL_Init(SDL_INIT_GAMECONTROLLER) == 0); if (initSuccess) { int joystickCount = SDL_NumJoysticks(); for (int i = 0; i < joystickCount; i++) { SDL_GameController* controller = SDL_GameControllerOpen(i); if (controller) { SDL_JoystickID id = getInstanceId(controller); Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; } } _isInitialized = true; } else { qDebug() << "Error initializing SDL"; } #endif }
void list_joysticks() { int num_joysticks = SDL_NumJoysticks(); if (num_joysticks == 0) { printf("No joysticks were found\n"); } else { printf("Found %d joystick(s)\n\n", num_joysticks); for(int joy_idx = 0; joy_idx < num_joysticks; ++joy_idx) { SDL_Joystick* joy = SDL_JoystickOpen(joy_idx); if (!joy) { fprintf(stderr, "Unable to open joystick %d\n", joy_idx); } else { SDL_GameController* gamepad = SDL_GameControllerOpen(joy_idx); print_joystick_info(joy_idx, joy, gamepad); if (gamepad) { SDL_GameControllerClose(gamepad); } SDL_JoystickClose(joy); } } } }
Game::Game(){ SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER); SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"); this->mainWindow = SDL_CreateWindow("Highway Crossing Frog", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, this->width, this->height, SDL_WINDOW_SHOWN); this->mainRenderer = SDL_CreateRenderer(this->mainWindow, -1, SDL_RENDERER_ACCELERATED); if(SDL_GameControllerAddMapping(GASIA_PS2_MAP) == 1){ printf("Managed to add silly PS2 adapter thing.\n"); } if(SDL_GameControllerAddMapping(GASIA_PS2_LIN) == 1){ printf("Managed to add silly PS2 adapter thing on Linux.\n"); } if(SDL_NumJoysticks() > 0){ for (int i = 0; i < SDL_NumJoysticks(); i++) { if(SDL_IsGameController(i)){ this->gamePad = SDL_GameControllerOpen(i); if(this->gamePad){ printf("Opened controller %i\n", i); } else { printf("Failed to open controller %i\n", i); } } } } else { printf("No controllers found.\n"); } this->gWorld = new GameWorld(this->mainRenderer); this->running = true; }
void SDL2Manager::init() { #ifdef HAVE_SDL2 bool initSuccess = (SDL_Init(SDL_INIT_GAMECONTROLLER) == 0); if (initSuccess) { int joystickCount = SDL_NumJoysticks(); for (int i = 0; i < joystickCount; i++) { SDL_GameController* controller = SDL_GameControllerOpen(i); if (controller) { SDL_JoystickID id = getInstanceId(controller); if (!_openJoysticks.contains(id)) { Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; auto userInputMapper = DependencyManager::get<UserInputMapper>(); joystick->registerToUserInputMapper(*userInputMapper); joystick->assignDefaultInputMapping(*userInputMapper); emit joystickAdded(joystick); } } } _isInitialized = true; } else { qDebug() << "Error initializing SDL2 Manager"; } #endif }
void Joystick::openController() { closeController(); if (!SDL_IsGameController(m_deviceIndex)) { return; } m_controllerHandle = SDL_GameControllerOpen(m_deviceIndex); }
// Opens up to 4 currently connected controllers void InputEngine::openControllers() { for (int i = 0; i < SDL_NumJoysticks() && i < MAX_NUM_CONTROLLERS; i++) { controllers[i] = SDL_GameControllerOpen(i); } std::cout << "NUM CONTROLLERS: " << SDL_NumJoysticks() << std::endl; }
void InputDaemon::addInputDevice(int index) { SDL_Joystick *joystick = SDL_JoystickOpen(index); if (joystick) { SDL_JoystickID tempJoystickID = SDL_JoystickInstanceID(joystick); if (!joysticks->contains(tempJoystickID)) { QSettings *settings = new QSettings(PadderCommon::configFilePath, QSettings::IniFormat); settings->beginGroup("Mappings"); QString temp; SDL_JoystickGUID tempGUID = SDL_JoystickGetGUID(joystick); char guidString[65] = {'0'}; SDL_JoystickGetGUIDString(tempGUID, guidString, sizeof(guidString)); temp = QString(guidString); bool disableGameController = settings->value(QString("%1Disable").arg(temp), false).toBool(); if (SDL_IsGameController(index) && !disableGameController) { SDL_GameController *controller = SDL_GameControllerOpen(index); if (controller) { SDL_Joystick *sdlStick = SDL_GameControllerGetJoystick(controller); SDL_JoystickID tempJoystickID = SDL_JoystickInstanceID(sdlStick); if (!joysticks->contains(tempJoystickID)) { GameController *damncontroller = new GameController(controller, index, this); joysticks->insert(tempJoystickID, damncontroller); trackcontrollers.insert(tempJoystickID, damncontroller); // Force close of settings file. settings->endGroup(); delete settings; settings = 0; emit deviceAdded(damncontroller); } } } else { Joystick *curJoystick = new Joystick(joystick, index, this); joysticks->insert(tempJoystickID, curJoystick); trackjoysticks.insert(tempJoystickID, curJoystick); // Force close of settings file. settings->endGroup(); delete settings; settings = 0; emit deviceAdded(curJoystick); } } } }
static void initInput(SDLInputContext* sdlIC) { for (int i = 0; i < MAX_SDL_CONTROLLERS; i++) { if (SDL_IsGameController(i)) { if(!(sdlIC->controllers[i] = SDL_GameControllerOpen(i))){ printSDLErrorAndExit(); } } } }
SDLController::SDLController(int j_idx) : m_Ctrl(0) { m_Ctrl = SDL_GameControllerOpen(j_idx); if (!m_Ctrl) { throw Wobbly("Couldn't open controller: %s", SDL_GetError()); } //const char *name = SDL_GameControllerNameForIndex(j_idx); }
void IN_StartupJoystick (void) { int i; int nummappings; char controllerdb[MAX_OSPATH]; SDL_GameController *gamecontroller; if (COM_CheckParm("-nojoy")) return; if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1 ) { Con_Warning("could not initialize SDL Game Controller\n"); return; } // Load additional SDL2 controller definitions from gamecontrollerdb.txt q_snprintf (controllerdb, sizeof(controllerdb), "%s/gamecontrollerdb.txt", com_basedir); nummappings = SDL_GameControllerAddMappingsFromFile(controllerdb); if (nummappings > 0) Con_Printf("%d mappings loaded from gamecontrollerdb.txt\n", nummappings); // Also try host_parms->userdir if (host_parms->userdir != host_parms->basedir) { q_snprintf (controllerdb, sizeof(controllerdb), "%s/gamecontrollerdb.txt", host_parms->userdir); nummappings = SDL_GameControllerAddMappingsFromFile(controllerdb); if (nummappings > 0) Con_Printf("%d mappings loaded from gamecontrollerdb.txt\n", nummappings); } for (i = 0; i < SDL_NumJoysticks(); i++) { const char *joyname = SDL_JoystickNameForIndex(i); if ( SDL_IsGameController(i) ) { const char *controllername = SDL_GameControllerNameForIndex(i); gamecontroller = SDL_GameControllerOpen(i); if (gamecontroller) { Con_Printf("detected controller: %s\n", controllername != NULL ? controllername : "NULL"); joy_active_instaceid = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(gamecontroller)); joy_active_controller = gamecontroller; break; } else { Con_Warning("failed to open controller: %s\n", controllername != NULL ? controllername : "NULL"); } } else { Con_Warning("joystick missing controller mappings: %s\n", joyname != NULL ? joyname : "NULL" ); } } }
void get_controller(void){ if(SDL_NumJoysticks() == 1){ printf("Dualshock3 connected, initializing...\n"); controller = SDL_GameControllerOpen(0); } else { printf("Dualshock3 not connected.\n"); controller = NULL; } }
void Renderer::detect_gamepads(){ if(SDL_NumJoysticks() >= 1){ std::cout << "Found one or more gamepads! Using '" << SDL_GameControllerNameForIndex(0) << "'" << std::endl; gamepad = SDL_GameControllerOpen(0); } else { std::cout << "No gamepads found. You will be able to control the visualization with mouse & keyboard." << std::endl; gamepad = NULL; } }
void JoystickScriptingInterface::update() { #ifdef HAVE_SDL2 if (_isInitialized) { PerformanceTimer perfTimer("JoystickScriptingInterface::update"); SDL_GameControllerUpdate(); SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_CONTROLLERAXISMOTION) { Joystick* joystick = _openJoysticks[event.caxis.which]; if (joystick) { joystick->handleAxisEvent(event.caxis); } } else if (event.type == SDL_CONTROLLERBUTTONDOWN || event.type == SDL_CONTROLLERBUTTONUP) { Joystick* joystick = _openJoysticks[event.cbutton.which]; if (joystick) { joystick->handleButtonEvent(event.cbutton); } if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { // this will either start or stop a global back event QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFBackEvent::startType() : HFBackEvent::endType(); HFBackEvent backEvent(backType); qApp->sendEvent(qApp, &backEvent); } else if (event.cbutton.button == SDL_CONTROLLER_BUTTON_A) { // this will either start or stop a global action event QEvent::Type actionType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFActionEvent::startType() : HFActionEvent::endType(); // global action events fire in the center of the screen HFActionEvent actionEvent(actionType, Application::getInstance()->getCamera()->computeViewPickRay(0.5f, 0.5f)); qApp->sendEvent(qApp, &actionEvent); } } else if (event.type == SDL_CONTROLLERDEVICEADDED) { SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which); SDL_JoystickID id = getInstanceId(controller); Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; emit joystickAdded(joystick); } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { Joystick* joystick = _openJoysticks[event.cdevice.which]; _openJoysticks.remove(event.cdevice.which); emit joystickRemoved(joystick); } } } #endif }
void SDL2Manager::pluginUpdate(float deltaTime, bool jointsCaptured) { #ifdef HAVE_SDL2 if (_isInitialized) { auto userInputMapper = DependencyManager::get<UserInputMapper>(); for (auto joystick : _openJoysticks) { joystick->update(deltaTime, jointsCaptured); } PerformanceTimer perfTimer("SDL2Manager::update"); SDL_GameControllerUpdate(); SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_CONTROLLERAXISMOTION) { Joystick* joystick = _openJoysticks[event.caxis.which]; if (joystick) { joystick->handleAxisEvent(event.caxis); } } else if (event.type == SDL_CONTROLLERBUTTONDOWN || event.type == SDL_CONTROLLERBUTTONUP) { Joystick* joystick = _openJoysticks[event.cbutton.which]; if (joystick) { joystick->handleButtonEvent(event.cbutton); } if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { // this will either start or stop a global back event QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFBackEvent::startType() : HFBackEvent::endType(); HFBackEvent backEvent(backType); qApp->sendEvent(qApp, &backEvent); } } else if (event.type == SDL_CONTROLLERDEVICEADDED) { SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which); SDL_JoystickID id = getInstanceId(controller); if (!_openJoysticks.contains(id)) { Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; joystick->registerToUserInputMapper(*userInputMapper); joystick->assignDefaultInputMapping(*userInputMapper); emit joystickAdded(joystick); } } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { Joystick* joystick = _openJoysticks[event.cdevice.which]; _openJoysticks.remove(event.cdevice.which); userInputMapper->removeDevice(joystick->getDeviceID()); emit joystickRemoved(joystick); } } } #endif }
int init_engine(SDL_GLContext *context, SDL_Window *window) { int img_flags = IMG_INIT_PNG; if (!(IMG_Init(img_flags) & img_flags)) { printf("SD_image could not initialize! SDL_image Error: %s\n", IMG_GetError()); return -1; } if (init_gl(context, window)) return -1; if (init_glew()) return -1; // if (init_effects(shader_programs, shader_infos, LENGTH(shader_programs))) { // printf("Something went wrong with shader program initialization!\n"); // return -1; // } load_effects( effects.all, LENGTH(effects.all), shader_file_paths, LENGTH(shader_file_paths), attribute_strings, LENGTH(attribute_strings), uniform_strings, LENGTH(uniform_strings)); open_simplex_noise(open_simplex_noise_seed, &osnctx); SDL_GameControllerEventState(SDL_ENABLE); /* Open the first available controller. */ SDL_GameController *controller = NULL; for (int i = 0; i < SDL_NumJoysticks(); ++i) { printf("Testing controller %i\n", i); if (SDL_IsGameController(i)) { controller = SDL_GameControllerOpen(i); if (controller) { printf("Successfully opened controller %i\n", i); break; } else { printf("Could not open gamecontroller %i: %s\n", i, SDL_GetError()); } } else { printf("Controller %i is not a controller?\n", i); } } init_keyboard(); init_render(); //Located in render.c if (signal(SIGUSR1, reload_signal_handler) == SIG_ERR) { printf("An error occurred while setting a signal handler.\n"); } return 0; }
bool GameController::enable() { if (isEnabled()) return true; Joystick::enable(); _sdlController = SDL_GameControllerOpen(getIndex()); if (!_sdlController) return false; return true; }
void OVR_SDL2_app::game_connect(int device, bool connected) { controller.resize(device + 1); if (controller[device]) SDL_GameControllerClose(controller[device]); if (connected) controller[device] = SDL_GameControllerOpen(device); else controller[device] = 0; }
/* * SDL.gameControllerOpen(index) * * Arguments: * index the controller index * * Returns: * The controller object or nil on failure * The error message */ static int l_gameControllerOpen(lua_State *L) { int index = luaL_checkinteger(L, 1); SDL_GameController *c; c = SDL_GameControllerOpen(index); if (c == NULL) return commonPushSDLError(L, 1); return commonPush(L, "p", GameCtlName, c); }
bool Joystick::attachGameController(int which) { Q_ASSERT(device_attached != true); controller = SDL_GameControllerOpen(which); if (controller == nullptr) { qCWarning(phxInput, "Joystick: Unable to open sdl game controller: %s", SDL_GetError()); return false; } setDeviceName(SDL_GameControllerName(controller)); device_attached = true; return true; }
void add_controller(int32_t deviceIndex) { // Find an empty slot in the controller array for (int i = 0; i < MAX_CONTROLLERS; i++) { if (controllers[i] == NULL) { // Open the controller controllers[i] = SDL_GameControllerOpen(deviceIndex); return; } } printf("No more controllers can be added\n"); }
void test_gamecontroller(int gamecontroller_idx) { SDL_GameController* gamepad = SDL_GameControllerOpen(gamecontroller_idx); if (!gamepad) { printf("error: not a gamecontroller\n"); } else { test_gamecontroller_events(gamepad); SDL_GameControllerClose(gamepad); } }
void DecafSDL::openInputDevices() { mVpad0Config = nullptr; mVpad0Controller = nullptr; for (const auto &device : config::input::devices) { if (config::input::vpad0.compare(device.id) != 0) { continue; } if (device.type == config::input::Joystick) { auto numJoysticks = SDL_NumJoysticks(); for (int i = 0; i < numJoysticks; ++i) { if (!SDL_IsGameController(i)) { continue; } auto controller = SDL_GameControllerOpen(i); if (!controller) { gCliLog->error("Failed to open game controller {}: {}", i, SDL_GetError()); continue; } auto name = SDL_GameControllerName(controller); if (!device.device_name.empty() && device.device_name.compare(name) != 0) { SDL_GameControllerClose(controller); continue; } mVpad0Controller = controller; break; } if (!mVpad0Controller) { continue; } } mVpad0Config = &device; break; } if (!mVpad0Config) { gCliLog->warn("No input device found for gamepad (VPAD0)"); } }
bool Joystick::openGamepad(int deviceindex) { if (!SDL_IsGameController(deviceindex)) return false; if (isGamepad()) { SDL_GameControllerClose(controller); controller = nullptr; } controller = SDL_GameControllerOpen(deviceindex); return isGamepad(); }
void InputDaemon::refreshMapping(QString mapping, InputDevice *device) { bool found = false; for (int i=0; i < SDL_NumJoysticks() && !found; i++) { SDL_Joystick *joystick = SDL_JoystickOpen(i); SDL_JoystickID joystickID = SDL_JoystickInstanceID(joystick); if (device->getSDLJoystickID() == joystickID) { found = true; if (SDL_IsGameController(i)) { // Mapping string updated. Perform basic refresh QByteArray tempbarray = mapping.toUtf8(); SDL_GameControllerAddMapping(tempbarray.data()); } else { // Previously registered as a plain joystick. Add // mapping and check for validity. If SDL accepts it, // close current device and re-open as // a game controller. SDL_GameControllerAddMapping(mapping.toUtf8().constData()); if (SDL_IsGameController(i)) { device->closeSDLDevice(); trackjoysticks.remove(joystickID); joysticks->remove(joystickID); SDL_GameController *controller = SDL_GameControllerOpen(i); GameController *damncontroller = new GameController(controller, i, settings, this); connect(damncontroller, SIGNAL(requestWait()), eventWorker, SLOT(haltServices())); SDL_Joystick *sdlStick = SDL_GameControllerGetJoystick(controller); joystickID = SDL_JoystickInstanceID(sdlStick); joysticks->insert(joystickID, damncontroller); trackcontrollers.insert(joystickID, damncontroller); emit deviceUpdated(i, damncontroller); } } } // Make sure to decrement reference count SDL_JoystickClose(joystick); } }
/* * Open controllers and joysticks */ void S2D_OpenControllers() { char guid_str[33]; // Enumerate joysticks for (int device_index = 0; device_index < SDL_NumJoysticks(); ++device_index) { // Check if joystick supports SDL's game controller interface (a mapping is available) if (SDL_IsGameController(device_index)) { SDL_GameController *controller = SDL_GameControllerOpen(device_index); SDL_JoystickID intance_id = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller)); SDL_JoystickGetGUIDString( SDL_JoystickGetGUID(SDL_GameControllerGetJoystick(controller)), guid_str, 33 ); if (intance_id > last_intance_id) { if (controller) { S2D_Log(S2D_INFO, "Controller #%i: %s\n GUID: %s", intance_id, SDL_GameControllerName(controller), guid_str); } else { S2D_Log(S2D_ERROR, "Could not open controller #%i: %s", intance_id, SDL_GetError()); } last_intance_id = intance_id; } // Controller interface not supported, try to open as joystick } else { SDL_Joystick *joy = SDL_JoystickOpen(device_index); SDL_JoystickID intance_id = SDL_JoystickInstanceID(joy); if (!joy) { S2D_Log(S2D_ERROR, "Could not open controller"); } else if(intance_id > last_intance_id) { SDL_JoystickGetGUIDString( SDL_JoystickGetGUID(joy), guid_str, 33 ); S2D_Log(S2D_INFO, "Controller #%i: %s\n GUID: %s\n Axes: %d\n Buttons: %d\n Balls: %d", intance_id, SDL_JoystickName(joy), guid_str, SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumBalls(joy) ); S2D_Log(S2D_WARN, "Controller #%i does not have a mapping available", intance_id); last_intance_id = intance_id; } } } }
void init() { u32 maxJoysticks = SDL_NumJoysticks(); u32 controllerIndex = 0; for (u32 joystickIndex = 0; joystickIndex < maxJoysticks; joystickIndex++) { if (!SDL_IsGameController(joystickIndex)) continue; if (controllerIndex >= MaximumControllers) break; g_controllerHandles[controllerIndex] = SDL_GameControllerOpen(joystickIndex); controllerIndex++; } }
void GameEngine::CaptureJoystick(int id){ if (SDL_IsGameController(id)){ m_gameController = SDL_GameControllerOpen(id); if(m_gameController){ #ifdef DEBUG const char *name = SDL_GameControllerName(m_gameController); std::cout << "Found a valid controller at index " << id << ", named: " << name << std::endl; delete name; #endif } else{ std::cout << "Error while capturing game controller " << SDL_GetError() << std::endl; } } }