Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] Gamepad not working on macOS #3651

Open
4 tasks done
NitroPlum opened this issue Dec 18, 2023 · 7 comments
Open
4 tasks done

[rcore] Gamepad not working on macOS #3651

NitroPlum opened this issue Dec 18, 2023 · 7 comments
Labels
help needed - please! I need help with this issue platform: macOS macOS platform

Comments

@NitroPlum
Copy link

Please, before submitting a new issue verify and check:

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

Gamepad input not working. I tried 2 different controllers.

  • Xbox One Series X connected via USB
    • IsGamepadAvailable(0) returns false.
  • Nintendo Switch Pro Controller connected via USB
    • IsGamepadAvailable(0) returns true.
    • No button input is ever detected

Environment

MacOSX Ventura on an M2 Mac.

Issue Screenshot

Can't really show this.

Code Example

#include "raylib.h"
#include <stdio.h>

int main(void)
{
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "Gamepads Broken");

    SetTargetFPS(60);               

    while (!WindowShouldClose()) 
    {
        BeginDrawing();

            ClearBackground(RAYWHITE);

            if(IsGamepadAvailable(0)) {
                DrawText("FOUND GAMEPAD TEST", 190, 275, 20, PURPLE);
                
                if(IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) {
                    DrawText("BUTTON PRESSED", 190, 350, 20, PURPLE);
                }
            }

        EndDrawing();
    }
    CloseWindow();        

    return 0;
}

Provide minimal reproduction code to test the issue. Please, format the code properly and try to keep it as simple as possible, just focusing on the experienced issue.

@ghost
Copy link

ghost commented Dec 18, 2023

@NitroPlum GLFW or SDL?

Either way:

  1. Regarding Nintendo Switch Pro Controller, it's on the mappings list (L950-L951) for Mac OS X.
    No button input being detected could be a binding issue.

  2. Regarding Xbox One Series X, couldn't find it on the mappings list and neither on the SDL_GameControllerDB.
    Probably why it's not being detected.

Edits: 1. added more information; 2. updated info, formatting.

@NitroPlum
Copy link
Author

After GLFW, I also tried the SDL backend. Is there a way for me to fix the binding issue locally @ubkp ?

@NitroPlum
Copy link
Author

Oh, another bit of info that may help. I did try in the browser examples on the Raylib site and both controllers work there.

@ghost
Copy link

ghost commented Dec 18, 2023

After GLFW, I also tried the SDL backend. Is there a way for me to fix the binding issue locally @ubkp ?

@NitroPlum Sure, create your own binds (you may want to take a look at SDL_GameControllerDB) and add it to your local src/external/glfw/src/mappings.h file.

Oh, another bit of info that may help. I did try in the browser examples on the Raylib site and both controllers work there.

AFAIK, the web browser gamepad API is a completely different thing (ref1, ref2).

Edit 1: AFAIK sometimes firmware updates end up changing the device GUID, which causes it to no longer match the DB. I could be wrong, but I think that happened to some Xbox controllers.

Edit 2: Apparently you can even use Steam's Big Picture mode to generate binds these days (ref).

@raysan5 raysan5 changed the title [Core] Gamepad not working on MacOSX [rcore] Gamepad not working on macOS Dec 19, 2023
@SoloByte
Copy link

SoloByte commented Jan 30, 2024

I have similar problems. I am using the c# bindings of raylib on MacOSX 14.2.1 Sonoma and gamepad input is no longer working. Raylib detects the connected gamepads but does not trigger any button/ trigger/ axis functions.

I have tested Xbox Elite Controller 2 & Xbox Series X Controller.

  • I can connect them fine to my mac
  • The input works with the raylib example in the browsers
  • The input works with a gamepad test online
  • Both gamepads work on windows with various games
  • I have used the exact same setup before (in october I think) and everything has worked fine.

At same point it just stopped working for me....

The example I am using to test this all out works fine on windows (the gamepad is detected & the input is detected)

I think the only thing I did was update the firmware on my elite controller but the other controller I did not update...

I have tried to use custom bindings and bindings from SDL_GameControllerDB with the SetGamepadMappings function but it did not change anything.

@raysan5 raysan5 added the platform: macOS macOS platform label Jan 31, 2024
@raysan5
Copy link
Owner

raysan5 commented Apr 21, 2024

@SoloByte Thanks for reporting. Could you try with raylib latest master branch version?

raylib 5.0 (November 2023) implemented a big redesign for desktop platforms and despite everything was carefully tested, some things could not work as expected.

I don't have a macOS, neither those mentioned gamepads, I need help to fix this issue.

@raysan5 raysan5 added the help needed - please! I need help with this issue label Apr 21, 2024
@SoloByte
Copy link

SoloByte commented Apr 21, 2024

@raysan5
I have just tested it on my MacBook with raylib cs 6.0.0. (I can only test raylib cs) I have used 3 xbox one controllers (elite series2, new-ish xbox one, old xbox one).

All three are detected by my MacBook, all three work on windows, all three work with a gamepad tester. I have tested them with the raylib input gamepad example and they are detected and the input works (even when more than 1 is connected) but it seems that the triggers are not detected at all (Left/Right Trigger). The joystick axis work fine.

I have tested it with my simple raylib cs gamepad tester project and the controllers are detected but no input is registered.

  • Raylib.IsGamepadAvailable(0) returns true (also for 2nd, 3rd connected gamepad)
  • Raylib.IsGamepadButtonDown(0, GamepadButton.RightFaceDown) always returns false
  • Raylib.GetGamepadButtonPressed() > 0 always returns false

It would be helpful if someone could test this on a Mac with raylib, because I can only test it with raylib C# bindings.

I will post my simple project here. It is possible that I am doing something wrong or missing a step.

//Using Raylib Cs 6.0.0 (Released 20 January 2024)
using Raylib_cs;


namespace GamepadCs
{
    public static class Program
    {
        public static int Main(string[] args)
        {
            //Init
            Raylib.InitWindow(800, 800, "Raylib cs Gamepad Test");
            Raylib.InitAudioDevice();
            Raylib.ClearWindowState(ConfigFlags.VSyncHint);
            Raylib.SetTargetFPS(60);

            var defaultFont = Raylib.GetFontDefault();
            
            //Gameloop
            while (!Raylib.WindowShouldClose())
            {
                Raylib.BeginDrawing();

                //Gamepad connected
                if (Raylib.IsGamepadAvailable(0))
                {
                    
                    //Xbox A button down
                    if (Raylib.IsGamepadButtonDown(0, GamepadButton.RightFaceDown))
                    {
                        Raylib.ClearBackground(Color.Green);
                    }
                    //any gamepad button pressed
                    else if (Raylib.GetGamepadButtonPressed() > 0)
                    {
                        Raylib.ClearBackground(Color.Yellow);
                    }
                    else //no gamepad button pressed
                    {
                        
                        //Left Mouse Button or Space is held down
                        if (Raylib.IsMouseButtonDown(MouseButton.Left) || Raylib.IsKeyDown(KeyboardKey.Space))
                        {
                            Raylib.ClearBackground(Color.Blue);
                        }
                        
                        //nothing pressed 
                        else
                        {
                            Raylib.ClearBackground(Color.DarkGray);
                        }
                    }
                }
                
                // no gamepad connected
                else 
                {

                    //Left Mouse Button or Space is held down
                    if (Raylib.IsMouseButtonDown(MouseButton.Left) || Raylib.IsKeyDown(KeyboardKey.Space))
                    {
                        Raylib.ClearBackground(Color.Purple);
                    }
                    
                    //nothing pressed 
                    else 
                    {
                        Raylib.ClearBackground(Color.Black);
                    }
                }
                
                Raylib.EndDrawing();
            }
            
            
            //End
            Raylib.CloseAudioDevice();
            Raylib.CloseWindow();
            return 0;
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help needed - please! I need help with this issue platform: macOS macOS platform
Projects
None yet
Development

No branches or pull requests

3 participants