2

I have a pretty simple program. I'm just trying to acknowledge keyboard/mouse events, but I'm getting no log output (inside my SDL_PollEvent loop). I'm running just basic Raspian (no X).

#include <bcm_host.h>
#include <SDL.h>
#include <SDL_opengles2.h>
#include <iostream>
using namespace std;

int main(int argc, char** argv)
{
    bcm_host_init();
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_DisplayMode mode;
    SDL_GetDesktopDisplayMode(0, &mode);
    cout << mode.w << 'x' << mode.h << endl;

    auto window = SDL_CreateWindow(
        "Test",
        0,
        0,
        mode.w,
        mode.h,
        SDL_WINDOW_OPENGL);
    if (!window)
    {
        cerr << "failed to make window: " << SDL_GetError() << '\n';
    }
    else
    {
        cout << "window created!\n";
        SDL_SetWindowFullscreen(window, SDL_TRUE);
        auto context = SDL_GL_CreateContext(window);
        if (context)
        {
            cout << (const char*)glGetString(GL_VERSION) << endl;
            glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
            SDL_Event event;
            bool running = true;
            int n = 0;
            while (running && n < 10)
            {
                glClear(GL_COLOR_BUFFER_BIT);
                SDL_GL_SwapWindow(window);
                cout << "pulse " << ++n << endl;
                while (SDL_PollEvent(&event))
                {
                    cout << "EVENT" << endl;
                    if (event.type == SDL_MOUSEMOTION) cout << "mouse move" << endl;
                    if (event.type == SDL_MOUSEBUTTONDOWN ||
                        event.type == SDL_KEYDOWN) running = false;
                }
                SDL_Delay(500);
            }
            SDL_GL_DeleteContext(context);
        }
        else
        {
            cerr << "failed to make context: " << SDL_GetError() << '\n';
        }
        SDL_DestroyWindow(window);
    }
    SDL_Quit();
    return 0;
}

I've tried messing with the flags passed to SDL_CreateWindow (such as SDL_WINDOW_INPUT_FOCUS and SDL_WINDOW_MOUSE_FOCUS) with no luck. The OpenGL works just fine, though: I get my colored screen (and even a visible mouse cursor in the upper left corner).

  • Why didn't you ask about this on SO?!? What makes you think it is a pi specific issue? – goldilocks Jan 11 '16 at 1:42
  • The addition of bcm_host.h is a (mostly) Pi-specific component. Also, Pi is what I'm working on and has the distinction of being able to run OpenGL applications without X. – TheBuzzSaw Jan 11 '16 at 1:44
  • Ah. I notice they dropped the generic framebuffer support at some point, so I guess that is true. However I don't think your code requires that context. I'm mentioning this because you could be waiting a long time around here, whereas if you test somewhere else and you have the same problem, then that makes finding advice quite a bit easier. – goldilocks Jan 11 '16 at 1:53
  • OK. Well, I don't have the same problem anywhere else. Other places have a more "normal" desktop environment, so event handling just works. The SDL code is clearly aware of Pi hardware (as noted in the build steps), but I'm clearly missing a step specific to Pi to capturing mouse/keyboard. – TheBuzzSaw Jan 11 '16 at 1:57
  • 1
    I know. That's a cookie cutter blurb that gets added. I and other people on SE have asked repeatedly for that to be changed to no avail. The point in this case is so that someone does not come along and answer the other question, or this question, and then someone else comes along later and answers the unanswered remaining one, or does not find the answered one, etc. As you point out, they do appear to be exactly the same issue. Hence they're duplicates and there is no point leaving them both open. If the OP of the other question disagrees and clarifies then I will open that one. – goldilocks Jan 11 '16 at 19:45
2

Make sure you have libudev development files installed.

sudo apt-get install libudev-dev

Then, rebuild and reinstall SDL 2. Mouse/keyboard input started working for me after I did that.

  • Thank you so much. This absolutely fixed everything. I thought I had made sure that a proper input library was in place, but I didn't. #fail – TheBuzzSaw Jan 17 '16 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.