diff --git a/examples/custom_scene_viewer/DemoWindow.cc b/examples/custom_scene_viewer/DemoWindow.cc index 9cb9c645b..95907ccd3 100644 --- a/examples/custom_scene_viewer/DemoWindow.cc +++ b/examples/custom_scene_viewer/DemoWindow.cc @@ -15,10 +15,11 @@ * */ -#if defined(__APPLE__) +#if __APPLE__ #include + #include #include -#elif !defined(_WIN32) +#else #include #include #include @@ -52,7 +53,11 @@ unsigned int imgh = 0; bool g_initContext = false; -#if not (__APPLE__ || _WIN32) +#if __APPLE__ + CGLContextObj g_context; + CGLContextObj g_glutContext; +#elif _WIN32 +#else GLXContext g_context; Display *g_display; GLXDrawable g_drawable; @@ -159,7 +164,10 @@ void printFPS() ////////////////////////////////////////////////// void displayCB() { -#if not (__APPLE__ || _WIN32) +#if __APPLE__ + CGLSetCurrentContext(g_context); +#elif _WIN32 +#else if (g_display) { glXMakeCurrent(g_display, g_drawable, g_context); @@ -171,7 +179,10 @@ void displayCB() camera->Capture(*g_image); -#if not (__APPLE__ || _WIN32) +#if __APPLE__ + CGLSetCurrentContext(g_glutContext); +#elif _WIN32 +#else glXMakeCurrent(g_glutDisplay, g_glutDrawable, g_glutContext); #endif @@ -198,7 +209,10 @@ void idleCB() ////////////////////////////////////////////////// void keyboardCB(unsigned char _key, int, int) { -#if not (__APPLE__ || _WIN32) +#if __APPLE__ + CGLSetCurrentContext(g_context); +#elif _WIN32 +#else if (g_display) { glXMakeCurrent(g_display, g_drawable, g_context); @@ -241,7 +255,10 @@ void keyboardCB(unsigned char _key, int, int) g_demo->SelectScene(index); } -#if not (__APPLE__ || _WIN32) +#if __APPLE__ + CGLSetCurrentContext(g_glutContext); +#elif _WIN32 +#else glXMakeCurrent(g_glutDisplay, g_glutDrawable, g_glutContext); #endif } @@ -259,9 +276,6 @@ void initCamera(CameraPtr _camera) ////////////////////////////////////////////////// void initContext() { - int argc = 0; - char **argv = 0; - glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE); glutInitWindowPosition(0, 0); glutInitWindowSize(imgw, imgh); @@ -278,6 +292,9 @@ void initContext() ////////////////////////////////////////////////// void run(ManualSceneDemoPtr _demo) { +#if __APPLE__ + g_context = CGLGetCurrentContext(); +#endif #if not (__APPLE__ || _WIN32) g_context = glXGetCurrentContext(); g_display = glXGetCurrentDisplay(); @@ -290,6 +307,9 @@ void run(ManualSceneDemoPtr _demo) initContext(); printUsage(); +#if __APPLE__ + g_glutContext = CGLGetCurrentContext(); +#endif #if not (__APPLE__ || _WIN32) g_glutDisplay = glXGetCurrentDisplay(); g_glutDrawable = glXGetCurrentDrawable(); diff --git a/examples/custom_scene_viewer/ManualSceneDemo.cc b/examples/custom_scene_viewer/ManualSceneDemo.cc index bf6d4c696..957ec6610 100644 --- a/examples/custom_scene_viewer/ManualSceneDemo.cc +++ b/examples/custom_scene_viewer/ManualSceneDemo.cc @@ -14,6 +14,16 @@ * limitations under the License. * */ + +#if defined(__APPLE__) + #include + #include +#elif not defined(_WIN32) + #include + #include + #include +#endif + #include #include #include "ManualSceneDemo.hh" @@ -169,8 +179,18 @@ void ManualSceneDemo::ChangeScene() ////////////////////////////////////////////////// ////////////////////////////////////////////////// -int main(int, char**) +int main(int _argc, char** _argv) { + glutInit(&_argc, _argv); + + // Expose engine name to command line because we can't instantiate both + // ogre and ogre2 at the same time + std::string ogre_engine("ogre"); + if (_argc > 1) + { + ogre_engine = _argv[1]; + } + common::Console::SetVerbosity(4); //! [add scenes] ManualSceneDemoPtr sceneDemo(new ManualSceneDemo); @@ -188,7 +208,7 @@ int main(int, char**) sceneDemo->AddScene(SceneBuilderPtr(new ShadowSceneBuilder(4))); sceneDemo->AddScene(SceneBuilderPtr(new ShadowSceneBuilder(5))); //! [add scenes] - sceneDemo->AddCamera("ogre"); + sceneDemo->AddCamera(ogre_engine); sceneDemo->AddCamera("optix"); sceneDemo->Run(); return 0;