cboe
cboe

Reputation: 477

SDL 2.0 iOS - Touch events not received

Here's how I initialize SDL:

//initialize engine and set main loop callback... kind of awkward is there a better way to do this?
extern "C"{
  CBCore::Engine *engine;

  void UpdateLoop(void *f)
  {
    engine->updateLoop();
  }

  int main(int argc, char *argv[])
  {
    engine = new CBCore::Engine();
    engine->init();
    Assert(engine->window(), "Window not set for iOS animation callback");
    SDL_iPhoneSetAnimationCallback(engine->window(), 1, UpdateLoop, NULL);

    return 0;  
  }
}


//init function of engine, initializes required SDL subsystems and creates window
void Engine::init()
{
  SDL_Log("Initializing engine!");
  /* initialize SDL */
  if(SDL_Init(0) != 0){
    Assert(0, "Could not initialize SDL");
  }

  if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
    Assert(0, "Could not initialize SDL Video");
  }

  if(SDL_InitSubSystem(SDL_INIT_TIMER) != 0){
    Assert(0, "Could not initialize SDL Timer");
  }

  _window = SDL_CreateWindow(NULL, 0, 0, 480, 320, SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL);
  Assert(_window, "Could not create window");

  _context = SDL_GL_CreateContext(pimpl->window);
  Assert(_context, "Could not create context");


  SDL_Log("Engine successfully initialized!");
}

//loop
void Engine::updateLoop()
{
  SDL_Event event;
  SDL_Log("Polling events");
  while(SDL_PollEvent(&event)) {
    SDL_Log("Polled event %d", event.type);
  }
}

The loop gets called and I get 4 Events at startup: SDL_APP_DIDENTERFOREGROUND, SDL_WINDOWEVENT_SIZE_CHANGED, SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_ENTER; I also got enter background messages and the likes. But I can click/touch on the simulator/device till the cows go home but no event is received... Am I missing something?

Upvotes: 1

Views: 1197

Answers (1)

cboe
cboe

Reputation: 477

I was finally able to solve it by calling SDL_GL_SwapWindow, after that events get processed.

Upvotes: 1

Related Questions