Example #1
0
Ogre::RenderWindow* RenderSystem::makeRenderWindow( intptr_t window_id, unsigned int width, unsigned int height )
{
  static int windowCounter = 0; // Every RenderWindow needs a unique name, oy.

  Ogre::NameValuePairList params;
  Ogre::RenderWindow *window = NULL;

  std::stringstream window_handle_stream;
  window_handle_stream << window_id;

#ifdef Q_OS_MAC
  params["externalWindowHandle"] = window_handle_stream.str();
#else
  params["parentWindowHandle"] = window_handle_stream.str();
#endif

  params["externalGLControl"] = true;

// Set the macAPI for Ogre based on the Qt implementation
#ifdef QT_MAC_USE_COCOA
  params["macAPI"] = "cocoa";
  params["macAPICocoaUseNSView"] = "true";
#else
  params["macAPI"] = "carbon";
#endif

  std::ostringstream stream;
  stream << "OgreWindow(" << windowCounter++ << ")";


  // don't bother trying stereo if Ogre does not support it.
#if !OGRE_STEREO_ENABLE
  force_no_stereo_ = true;
#endif

  // attempt to create a stereo window
  bool is_stereo = false;
  if (!force_no_stereo_)
  {
    params["stereoMode"] = "Frame Sequential";
    window = tryMakeRenderWindow( stream.str(), width, height, &params, 100);
    params.erase("stereoMode");

    if (window)
    {
#if OGRE_STEREO_ENABLE
      is_stereo = window->isStereoEnabled();
#endif
      if (!is_stereo)
      {
        // Created a non-stereo window.  Discard it and try again (below)
        // without the stereo parameter.
        ogre_root_->detachRenderTarget(window);
        window->destroy();
        window = NULL;
        stream << "x";
        is_stereo = false;
      }
    }
  }

  if ( window == NULL )
  {
    window = tryMakeRenderWindow( stream.str(), width, height, &params, 100);
  }

  if( window == NULL )
  {
    ROS_ERROR( "Unable to create the rendering window after 100 tries." );
    assert(false);
  }

  if (window)
  {
    window->setActive(true);
    //window->setVisible(true);
    window->setAutoUpdated(false);
  }

  stereo_supported_ = is_stereo;

  ROS_INFO_ONCE("Stereo is %s", stereo_supported_ ? "SUPPORTED" : "NOT SUPPORTED");

  return window;
}