1
Window / Re: OSX XBox Controller Z trigger and dpad not recognised
« on: November 10, 2023, 06:23:07 pm »
Great stuff. Thank you kindly.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Which controller are you using? It is an official Xbox one?
You mention that you get no input from the triggers. Although I'm pretty sure this isn't the issue, make sure you don't press them together.
It seems weird that the right analog stick is using Z and R for its axis when there are perfectly good pairs of axes for them (mine doesn't even use the R axis at all!).
Does this mean that you can only get input on left axis pair and Z/R pair (and all the buttons)? That is, none of the other axes are getting input at all?
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Window/Joystick.hpp>
#include <iostream>
std::string axisToString(const sf::Joystick::Axis axis) {
switch (axis) {
case sf::Joystick::Axis::PovX:
return "PovX";
case sf::Joystick::Axis::PovY:
return "PovY";
case sf::Joystick::Axis::R:
return "R";
case sf::Joystick::Axis::U:
return "U";
case sf::Joystick::Axis::V:
return "V";
case sf::Joystick::Axis::X:
return "X";
case sf::Joystick::Axis::Y:
return "Y";
case sf::Joystick::Axis::Z:
return "Z";
default:
return "";
}
}
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "Test Gamepad");
sf::Joystick::update();
std::vector<sf::Joystick::Axis> connectedAxis;
int numButtons = 0;
int gamePadIdx = -1;
for (int i = 0; i < sf::Joystick::Count; i++) {
if (sf::Joystick::isConnected(i)) {
gamePadIdx = i;
std::cout << "found connected gamepad at idx: " << gamePadIdx
<< std::endl;
numButtons = sf::Joystick::getButtonCount(gamePadIdx);
std::cout << "number of buttons: " << numButtons << std::endl;
connectedAxis.clear();
for (int i = sf::Joystick::Axis::X; i < sf::Joystick::AxisCount; i++) {
sf::Joystick::Axis axis = static_cast<sf::Joystick::Axis>(i);
if (sf::Joystick::hasAxis(gamePadIdx, axis)) {
std::cout << "has axis: " << axisToString(axis) << std::endl;
connectedAxis.push_back(axis);
}
}
break;
}
}
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed: {
std::cout << "shutting down" << std::endl;
window.close();
break;
}
case sf::Event::KeyPressed: {
if (event.key.code == sf::Keyboard::Escape) {
std::cout << "shutting down" << std::endl;
window.close();
}
break;
}
case sf::Event::JoystickConnected: {
// Don't override if there's already a joystick id
if (gamePadIdx == -1) {
gamePadIdx = event.joystickConnect.joystickId;
std::cout << "found connected gamepad at idx: " << gamePadIdx
<< std::endl;
numButtons = sf::Joystick::getButtonCount(gamePadIdx);
std::cout << "number of buttons: " << numButtons << std::endl;
connectedAxis.clear();
for (int i = sf::Joystick::Axis::X; i < sf::Joystick::AxisCount;
i++) {
sf::Joystick::Axis axis = static_cast<sf::Joystick::Axis>(i);
if (sf::Joystick::hasAxis(gamePadIdx, axis)) {
std::cout << "has axis: " << axisToString(axis) << std::endl;
connectedAxis.push_back(axis);
}
}
}
break;
}
case sf::Event::JoystickDisconnected: {
if (event.joystickConnect.joystickId == gamePadIdx) {
std::cout << "gamepad disconnected at idx: " << gamePadIdx
<< std::endl;
gamePadIdx = -1;
}
}
default:
break;
}
}
if (gamePadIdx != -1) {
// Log axis movement
static const float deadZone = 20.f;
for (int i = 0; i < connectedAxis.size(); i++) {
const float axisPos =
sf::Joystick::getAxisPosition(gamePadIdx, connectedAxis);
if (std::abs(axisPos) > deadZone) {
std::cout << "Axis: " << axisToString(connectedAxis)
<< ", Pos: " << axisPos << std::endl;
}
}
// Log button presses
for (int i = 0; i < numButtons; i++) {
if (sf::Joystick::isButtonPressed(gamePadIdx, i)) {
std::cout << "Button: " << i << " is pressed" << std::endl;
}
}
}
}
}
Unexpected usage for element of Page Generic Desktop: 0x1
Unexpected usage for element of Page Generic Desktop: 0x1
Joystick (vendor/product id: 0x45e/0xb20) range is an unexpected one: [1, 8]
found connected gamepad at idx: 0
number of buttons: 15
has axis: X
has axis: Y
has axis: Z
has axis: R
EDIT: For other poor souls like me with an Nvidia Optimus card please look into using the bumblebee graphics package as from my experience it is by far the most stable. You do have the inconvenience of needing to set which programs use your Nvidia card and which do not, but this is minor in comparison to your desktop freezing every 5 minutes (in my experience anyway).
What graphics hardware and driver are you using?
you can't force SFML to create a core context like you can in GLFW. This will change soon hopefully .
EDIT: On Windows, your code runs fine. So I am assuming it is a core context issue specific to Linux until gl_dev_new gets merged.
Mesa3D has this weird thing about not wanting to support compatibility contexts..
This is never a good idea. If people don't report issues so they can get fixed, you can't expect anything to change for the better . For all we know, you could still be misunderstanding something we all assume you understand right.
If you can post everything that is required for me to reproduce your application (all source files and shaders should be enough) then I can try to see what the problem could be. I use SFML with modern OpenGL all the time, and I haven't had any major issues so far (well... there are issues, but I know how to handle them ).
You always have to link the system module. The graphics, window, network and audio module all depend on it.
This worked. Thanks! As you instructed I removed the graphics library and replaced the header: <SFML/Graphics.hpp> with <SFML/Window.hpp> and sf::RenderWindow with sf::Window and now I get my triangle.
It's not mandatory, it will just make your life easier since you won't have to deal with SFML changing any states etc.
You shouldn't let the SFML example code confuse you. Just create an SFML window, set it active and you are good to go just like you would with those other libraries you know.
If you don't intend to use any sfml-graphics features (sprites, shapes, etc.) then you can completely ignore that module all together and use sfml-window by itself. sfml-window provides roughly the same functionality as GLFW (obviously with a different API) and is perfect if you just want to handle all the OpenGL stuff yourself.
To do this, simply replace your sf::RenderWindow with a simple sf::Window. It is a barebones target for OpenGL operations. You can also replace <SFML/Graphics.hpp> with <SFML/Window.hpp> in this case. Including <SFML/OpenGL.hpp> is also unnecessary since you already included the GLEW header before that.
Like I said, restrict yourself to the sfml-window module (sf::Window) and you should be good and all the stuff in the book should "just work".
SFML might one day support a backend that doesn't have to rely on the legacy API on capable hardware, and work is already under way to clean up a lot of the archaic stuff in the SFML code base.