我正在尝试将 SDL 2.0.3 集成到 Ogre 1.9.0 以进行窗口和事件处理,它在 Linux 下运行良好,但在 IOS 7.1 下我遇到了问题。
我无法从 SDL 获取任何输入或窗口事件。我正在使用 wmInfo.info.uikit.window 来获取句柄,然后将其传递给 Ogre。我唯一不确定的是我是否正确获取了 GL 上下文。当我使用 Ogre SDL_APP_DIDENTERFOREGROUND 启动 SDL 时,我只能得到一个事件。 IOS有什么特别需要我做的吗?
我非常感谢任何帮助,因为我遇到了上述问题。
我也在 OSX 和 IOS 7.1 模拟器下工作。以下是我对原始 Ogre iOS 模板的更改。
SDL 和 Ogre 初始化:
//SDL
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);
/* create window and renderer */
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);
m_pLog = Ogre:ogManager::getSingleton().createLog("OgreLogfile.log", true, true, false);
m_pLog->setDebugOutputEnabled(true);
String pluginsPath;
m_pRoot = new Ogre::Root(pluginsPath, Ogre::macBundlePath() + "/ogre.cfg");
m_StaticPluginLoader.load();
m_pRenderWnd = m_pRoot->initialise(false, wndTitle);
size_t winHandle = reinterpret_cast<size_t>(wmInfo.info.uikit.window);
size_t glHandle = reinterpret_cast<size_t>(glContext);
Ogre::NameValuePairList params;
params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)winHandle);
params["externalGLContext"] = Ogre::StringConverter::toString((unsigned long)glHandle);
params["externalGLControl"] = String("True");
m_pRenderWnd = m_pRoot->createRenderWindow("", displayMode.w/2, displayMode.h/2, false, ¶ms);
我的主循环:
DemoApp demo;
demo.startDemo();
bool done = false;
SDL_Event event;
double mStartTime;
double mLastFrameTime;
while (!done)
{
mStartTime = OgreFramework::getSingletonPtr()->m_pTimer->getMillisecondsCPU();
OgreFramework::getSingletonPtr()->updateOgre(mLastFrameTime);
OgreFramework::getSingletonPtr()->m_pRoot->renderOneFrame();
mLastFrameTime = OgreFramework::getSingletonPtr()->m_pTimer->getMillisecondsCPU() - mStartTime;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_FINGERMOTION:
SDL_Log("Finger Motion");
break;
case SDL_FINGERDOWN:
SDL_Log("Finger Down");
break;
case SDL_FINGERUP:
SDL_Log("Finger Up");
break;
case SDL_QUIT:
done = true;
break;
case SDL_APP_DIDENTERFOREGROUND:
SDL_Log("SDL_APP_DIDENTERFOREGROUND");
break;
case SDL_APP_DIDENTERBACKGROUND:
SDL_Log("SDL_APP_DIDENTERBACKGROUND");
break;
case SDL_APP_LOWMEMORY:
SDL_Log("SDL_APP_LOWMEMORY");
break;
case SDL_APP_TERMINATING:
SDL_Log("SDL_APP_TERMINATING");
break;
case SDL_APP_WILLENTERBACKGROUND:
SDL_Log("SDL_APP_WILLENTERBACKGROUND");
break;
case SDL_APP_WILLENTERFOREGROUND:
SDL_Log("SDL_APP_WILLENTERFOREGROUND");
break;
case SDL_WINDOWEVENT:
{
switch (event.window.event)
{
case SDL_WINDOWEVENT_RESIZED:
{
SDL_Log("Window %d resized to %dx%d", event.window.windowID, event.window.data1, event.window.data2);
break;
}
}
}
}
}
Best Answer-推荐答案 strong>
我意识到这个问题现在已经有几年了,但我遇到了同样的问题,我希望我的解决方案对其他人有用。
问题是您将 SDL 的 UIView (SDL_uikitview) 替换为 Ogre 的 UIView (OgreEAGL2View),因此您将不再接收任何触摸输入或通过 SDL_uikitviewcontroller 或 SDL_uikitview 实现的任何功能。此替换发生在 GLES2 RenderSystem 内部(特别是在 OgreEAGL2Window.mm 中)
我自己解决这个问题的方法是创建自己的 UIViewController 和 UIView,然后将该 View 置于 SDL 的 View 之后。然后,您可以从 SDL 的 View 接收触摸输入,同时渲染到 Ogre 的 View 中。这将需要创建一个 Objective-C 编译单元,代码如下所示:
#include "OgreEAGL2View.h"
#import <UIKit/UIWindow.h>
#import <UIKit/UIDevice.h>
// other includes
// call this from your C++ framework
// pass it your startup params
void setupMyiOSViews(Ogre::NameValuePairList ¶ms)
{
// grab the UIWindow (you must have called SDL_createwindow before calling this)
SDL_SysWMinfo wmInfo;
SDL_Window *sdlWindow;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(sdlWindow, &wmInfo);
UIWindow *w = wmInfo.info.uikit.window;
// get a rectangle with the screen dimensions
CGRect rect = [[UIScreen mainScreen] applicationFrame];
// instantiate a view controller of Ogre's subclass of UIViewController
EAGL2ViewController *myViewController = [[EAGL2ViewController alloc] init];
// instantiate a view of Ogre's subclass of UIView
EAGL2View *myView = [[EAGL2View alloc] initWithFrame:rect];
// make sure it's not transparent
myView.opaque = YES;
// attach the view to the viewcontroller
myViewController.view = myView;
// add the view to the current window
[w addSubview:myView];
// put the view *behind* the SDL view
[w sendSubviewToBack:myView];
// add the window, viewcontroller, and view to the proper parameters
// UIWindow maps to param: externalWindowHandle
// UIViewController maps to param: externalViewControllerHandle
// UIView maps to param: externalViewHandle
Ogre::String str_w = Ogre::StringConverter::toString((unsigned long)w);
Ogre::String str_vc = Ogre::StringConverter::toString((unsigned long)myViewController);
Ogre::String str_v = Ogre::StringConverter::toString((unsigned long)myView);
params["externalWindowHandle"] = str_w;
params["externalViewControllerHandle"] = str_vc;
params["externalViewHandle"] = str_v;
Ogre:ogManager::getSingleton().logMessage("externalWindowHandle: " + str_w);
Ogre:ogManager::getSingleton().logMessage("externalViewControllerHandle: " + str_vc);
Ogre:ogManager::getSingleton().logMessage("externalViewHandle: " + str_v);
// now pass params into Ogre::Root::createRenderWindow
}
请注意,甚至不需要使用 SDL 创建和上下文。 Ogre 现在将渲染到它自己的 View 和 View Controller 中
关于c++ - SDL 2.0.3 与 Ogre 1.9.0 和 IOS,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/25796462/
|