示例#1
0
void OgreRenderer::createWindow(const std::string &title, const WindowSettings& settings)
{
    assert(mRoot);
    mRoot->initialise(false);

    // create a hidden 1x1 background window to keep resources when recreating the secondary (real) window
    NameValuePairList params_;
    params_.insert(std::make_pair("title", title));
    params_.insert(std::make_pair("FSAA", "0"));
    params_.insert(std::make_pair("vsync", "false"));
    params_.insert(std::make_pair("hidden", "true"));
    Ogre::RenderWindow* hiddenWindow = mRoot->createRenderWindow("InactiveHidden", 1, 1, false, &params_);
    hiddenWindow->setActive(false);

    NameValuePairList params;
    params.insert(std::make_pair("title", title));
    params.insert(std::make_pair("FSAA", settings.fsaa));
    params.insert(std::make_pair("vsync", settings.vsync ? "true" : "false"));


    mWindow = mRoot->createRenderWindow(title, settings.window_x, settings.window_y, settings.fullscreen, &params);

    // create the semi-transparent black background texture used by the GUI.
    // has to be created in code with TU_DYNAMIC_WRITE_ONLY param
    // so that it can be modified at runtime.
    Ogre::TextureManager::getSingleton().createManual(
                    "transparent.png",
                    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                    Ogre::TEX_TYPE_2D,
                    1, 1,
                    0,
                    Ogre::PF_A8R8G8B8,
                    Ogre::TU_WRITE_ONLY);
}
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++ << ")";

#ifdef Q_WS_X11
    old_error_handler = XSetErrorHandler( &checkBadDrawable );
#endif

    int attempts = 0;
    while (window == NULL && (attempts++) < 100)
    {
        try
        {
            window = ogre_root_->createRenderWindow( stream.str(), width, height, false, &params );

            // If the driver bug happened, tell Ogre we are done with that
            // window and then try again.
            if( x_baddrawable_error )
            {
                ogre_root_->detachRenderTarget( window );
                window = NULL;
                x_baddrawable_error = false;
            }
        }
        catch( std::exception ex )
        {
            std::cerr << "rviz::RenderSystem: error creating render window: "
                      << ex.what() << std::endl;
            window = NULL;
        }
    }

#ifdef Q_WS_X11
    XSetErrorHandler( old_error_handler );
#endif

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

    if( attempts > 1 )
    {
        ROS_INFO( "Created render window after %d attempts.", attempts );
    }

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

    return window;
}
示例#3
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;
}