The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.
SDL
Simple Directmedia Layer Forums
Get UIView and UIViewController from SDL Window
Alexander Chaliovski
Guest
Posted: Sun Sep 14, 2014 11:11 am
Hi I am trying to get proper UIView and UIViewController from SDL Window and pass it to Ogre but the program crashes with [SDL_uikitopenglview setMWindowName:]: unrecognized selector sent to instance 0xa213940. I am not sure if I am doing it properly. My code is below.
   if (SDL_Init(SDL_INIT_VIDEO) < 0)
   {
       printf("Could not initialize SDL\n");
       return 1;
   }
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
 Â
   SDL_DisplayMode displayMode;
   SDL_GetDesktopDisplayMode(0, &displayMode);
   SDL_Window* window = SDL_CreateWindow(NULL, 0, 0, displayMode.w, displayMode.h, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_RESIZABLE);
   SDL_GLContext glContext = SDL_GL_CreateContext(window);
   SDL_SysWMinfo wmInfo;
   SDL_VERSION(&wmInfo.version);
   SDL_GetWindowWMInfo(window,&wmInfo);
Â
   //Objective-C
   UIWindow * appWindow = wmInfo.info.uikit.window;
   UIViewController * rootViewController = appWindow.rootViewController;
   UIView * myView = [appWindow.subviews objectAtIndex:0];
   //Passing the handles to Ogre
   Ogre::NameValuePairList params;
   params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)appWindow);
   params["externalViewHandle"] = Ogre::StringConverter::toString((unsigned long)myView);
   params["externalViewControllerHandle"] = Ogre::StringConverter::toString((unsigned long)rootViewController);