raylib icon indicating copy to clipboard operation
raylib copied to clipboard

[rcore] Gamepad detected, input not detected (linux)

Open Falconerd opened this issue 1 year ago • 1 comments

Hi Raysan, thank you for your time and Raylib.

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

Issue description

Gamepad is detected correctly, but no button presses or joystick movements are detected.

Environment

Arch Linux X11, OpenGL 4.6, Intel UHD Graphics 620

Issue Screenshot

2024-08-27_19-16-40

Code Example

I discovered the issue in my project that uses Odin, so I tested in C.

I have tried with a fresh build of cloned master using the examples/core_input_gamepad binary.

I also tested GLFW by itself and can confirm the gamepad is working there, using this code:

In Odin:

package main

import "core:fmt"
import "vendor:glfw"

main :: proc() {
    glfw.Init()
    window := glfw.CreateWindow(640, 480, "GLFW Gamepad Test", nil, nil)

    for !glfw.WindowShouldClose(window) {
        if glfw.JoystickIsGamepad(0) {
            fmt.println("Gamepad here")
        }

        button_states := glfw.GetJoystickButtons(0)
        fmt.println(button_states)

        glfw.SwapBuffers(window)
        glfw.PollEvents()
    }
}

In C, from glfw/master:

#include <stdio.h>
#include <GLFW/glfw3.h>

int main() {
    glfwInit();
    GLFWwindow *window = glfwCreateWindow(640, 480, "GLFW Gamepad Test", 0, 0);

    while (!glfwWindowShouldClose(window)) {
        if (glfwJoystickIsGamepad(0)) {
            printf("Gamepad here\n");
        }

        int count = 0;
        const unsigned char *button_states = glfwGetJoystickButtons(0, &count);

        for (int i = 0; i < count; i += 1) {
          printf("%d -> %d\n", i, button_states[i]);
        }

        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    return 0;
}

Gamepad does work for me on this page: https://www.raylib.com/examples/core/loader.html?name=core_input_gamepad

If there's anything I can do to help, please let me know.

Cheers, Dylan

Falconerd avatar Aug 27 '24 09:08 Falconerd

@Falconerd Thanks for reporting, it seems it could be related to ARch Linux but I'm afraid I don't have a paltform configured to review it. If anyone could confirm if it works in other Linux distributions...

raysan5 avatar Aug 27 '24 17:08 raysan5

@Falconerd which gamepad are you using?

Peter0x44 avatar Aug 29 '24 22:08 Peter0x44

@Falconerd which gamepad are you using?

Xbox Elite 2

Falconerd avatar Aug 29 '24 22:08 Falconerd

I have found some things I think are bugs with GLFW after some testing. glfw.GetGamepadState does not update the current state of the gamepad glfw.GetJoystickButtons does give the expected results glfw.JoystickIsGamepad always returns false

I'm going to take this issue over to GLFW.

Cheers.

Falconerd avatar Sep 02 '24 02:09 Falconerd

@Falconerd I have similar problems with my own controller I couldn't figure, I just used SDL for the inputs instead. You can use it alongside glfw if you're willing to call it specifically, or you can compile raylib to use it as a "backend". I did the former.

Peter0x44 avatar Sep 02 '24 02:09 Peter0x44

It seems the issue could be GLFW related, closing it.

raysan5 avatar Sep 03 '24 11:09 raysan5