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

OpenTK Gamepad: SDL_GameController #1

Open
flibitijibibo opened this issue Feb 15, 2013 · 3 comments
Open

OpenTK Gamepad: SDL_GameController #1

flibitijibibo opened this issue Feb 15, 2013 · 3 comments

Comments

@flibitijibibo
Copy link

I'll likely do this myself, but if someone wants to do this even sooner than me, here's the deal:

The joystick API for OpenTK is crap. To get any good mileage out of SDL2 we'd basically have to write our own API for OpenTK that revolves around us.

Oh, wait, we can do that! Because OpenTK has a GamePad driver in their Input module and it's totally unimplemented.

I say we just rip off SDL2's GameController API in there, then our SDL2 driver will map cleanly to it. It's also a hell of a lot nicer when we implement SDL2 controllers in MonoGame.

Here's the SDL2_GameController header, for reference:
http://hg.libsdl.org/SDL/file/700f1b25f77f/include/SDL_gamecontroller.h

If it turns out GameController isn't as flexible as I want it to be (axis flipping is one I'm concerned about...) it would still work pretty well with SDL_joystick.

@sulix
Copy link
Owner

sulix commented Feb 20, 2013

I've added the SDL_gamecontroller header to the API class: it shouldn't be hard to make the GamePad class in OpenTK wrap that. Otherwise, the (far more hacky) solution would just be to expose the API class directly and use if for MonoGame.

The SDL_GameController API lets you access the bindings to the underlying joystick directly, so it should be easy to add axis flipping if needed, or even to fall back to using the MonoGame gamepad config.

I'll leave implementing it up to you: my gamepad is so old it plugs into a SoundBlaster 16. You'll need to wrap any SDL call in a lock(API.sdl_api_lock) block, but other than that it should be pretty straightforward.

-- David

@sulix
Copy link
Owner

sulix commented Mar 24, 2013

Okay, there's an early revision of GamePad support in the opentk-sdl2 MonoGame branch. It didn't detect the joystick I plugged in, but I probably just stuffed up my SDL_CONTROLLERCONFIG env var.

I haven't implemented OpenTK's GamePad interface, but rather just opened up the raw SDL API to MonoGame. Hacky? Yes! At the moment only recognized SDL GameControllers should work (and even then, it't totally untested). I've vague plans to have it simply use the Joystick API and grab configs from GameController if they're around, but for now I'll stick with this.

If you want to give it a go, it all compiles and runs with Codename lolno. It'll spit a fair bit of debug to stdout, and hopefully it won't crash if it actually detects a controller it likes.

I'll see if I can fix it up later, but for the moment GamePad support is pretty low on the priority list.

-- David

@sulix
Copy link
Owner

sulix commented Apr 15, 2013

Fixed a crash issue with the raw bindings in the API class (can't wait to switch to SDL2#) We can detect controllers from Steam Big Picture now, though nothing actually works once they're done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants