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).

TheBuzzSaw
  • 123
  • 6

1 Answers1

3

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.

Josh
  • 46
  • 1