Esempio n. 1
0
void ApplicationContext::reconfigure(const Ogre::String &renderer, Ogre::NameValuePairList &options)
{
    mNextRenderer = renderer;
    Ogre::RenderSystem* rs = mRoot->getRenderSystemByName(renderer);

    // set all given render system options
    for (Ogre::NameValuePairList::iterator it = options.begin(); it != options.end(); it++)
    {
        rs->setConfigOption(it->first, it->second);

#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
        // Change the viewport orientation on the fly if requested
        if(it->first == "Orientation")
        {
            if (it->second == "Landscape Left")
                mWindow->getViewport(0)->setOrientationMode(Ogre::OR_LANDSCAPELEFT, true);
            else if (it->second == "Landscape Right")
                mWindow->getViewport(0)->setOrientationMode(Ogre::OR_LANDSCAPERIGHT, true);
            else if (it->second == "Portrait")
                mWindow->getViewport(0)->setOrientationMode(Ogre::OR_PORTRAIT, true);
        }
#endif
    }

#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
    // Need to save the config on iOS to make sure that changes are kept on disk
    mRoot->saveConfig();
#endif
    mRoot->queueEndRendering();   // break from render loop
}
Esempio n. 2
0
    void SceneWidget::updateOgreWindow()
    {
        if (mWindow)
        {
            Ogre::Root::getSingleton().destroyRenderTarget(mWindow);
            mWindow = NULL;
        }

        std::stringstream windowHandle;
        windowHandle << this->winId();

        std::stringstream windowTitle;
        static int count=0;
        windowTitle << ++count;

        Ogre::NameValuePairList params;

        params.insert(std::make_pair("externalWindowHandle",  windowHandle.str()));
        params.insert(std::make_pair("title", windowTitle.str()));
        params.insert(std::make_pair("FSAA", "0")); // TODO setting
        params.insert(std::make_pair("vsync", "false")); // TODO setting

        mWindow = Ogre::Root::getSingleton().createRenderWindow(windowTitle.str(), this->width(), this->height(), false, &params);
        mWindow->addViewport(mCamera)->setBackgroundColour(Ogre::ColourValue(0.3,0.3,0.3,1));

        Ogre::Real aspectRatio = Ogre::Real(width()) / Ogre::Real(height());
        mCamera->setAspectRatio(aspectRatio);
    }
Esempio n. 3
0
 void ConfigFile::addSection(const Ogre::String& section, const Ogre::NameValuePairList& settings)
 {
     // Create new section
     mSettings[section] = OGRE_NEW_T(SettingsMultiMap, MEMCATEGORY_GENERAL);
     // Insert values from the settings list
     mSettings[section]->insert(settings.begin(), settings.end());
 }
Esempio n. 4
0
GraphicsOgre::GraphicsOgre(const Options *config):
	ogre_{new Ogre::Root("", "")},
	window_{nullptr}
{
	LOG(INFO) << "Initializing Ogre";
	//use OpenGL
	const std::string pluginsFolder = config->getValue<std::string>("ogrePluginsFolder");
	ogre_->loadPlugin(pluginsFolder + "RenderSystem_GL");
	const Ogre::RenderSystemList renderList = ogre_->getAvailableRenderers();
	Ogre::RenderSystemList::const_iterator r_it;
	r_it = renderList.begin();
	ogre_->setRenderSystem(*r_it);
	ogre_->initialise(false);

	//create manualy the window
	Ogre::NameValuePairList opts;
	opts.insert(Ogre::NameValuePairList::value_type("vsync", "false"));
	opts.insert(Ogre::NameValuePairList::value_type("top", "10"));
	opts.insert(Ogre::NameValuePairList::value_type("left", "10"));
	window_ = ogre_->createRenderWindow(
		config->getValue<std::string>("appname"), 
		config->getValue<int>("width"), 
		config->getValue<int>("height"), 
		config->getValue<bool>("fullscreen"), 
		&opts);
	//initialize ressources	
	defineRessources();
	Ogre::ResourceGroupManager::getSingleton().loadResourceGroup("General");
}
//----------------------------------------------------------------------------------------
void MaterialEditorPrefsEditor::getPreferences(Ogre::NameValuePairList& preferences)
{
    preferences.insert(Ogre::NameValuePairList::value_type("fontSize",
        Ogre::StringConverter::toString(fontSizeSpinBox->value())));

    preferences.insert(Ogre::NameValuePairList::value_type("lineWrapping",
        Ogre::StringConverter::toString(lineBreakCheckBox->isChecked())));
}
/** Utility function for creating and inserting layer properties
@param layer Spacescape layer
@param insertAfter Property to insert after
@param minimize Minimize this layer
@return The created / inserted property
*/
QtProperty* QtSpacescapeMainWindow::insertLayerProperties(Ogre::SpacescapeLayer* layer, QtProperty *insertAfter, bool minimize)
{
    // turn refreshing flag on so we don't process valueChanged events
    mRefreshing = true;

    // get layer params
    Ogre::NameValuePairList params = layer->getParams();

    // create the layer properties object
    QtProperty *layerProperties = mPropertyManager->addProperty(
                QtVariantPropertyManager::groupTypeId(),
                QLatin1String(layer->getName().c_str())
    );

    // insert it into the property tree early so we can minize items inside
    ui->layerProperties->insertProperty(layerProperties, insertAfter);

    // minimize the layer - speeds things up!
    if(minimize) {
        ui->layerProperties->setExpanded(ui->layerProperties->topLevelItem(layerProperties), false);
    }

    // add the common layer params to the subproperties first
    layerProperties->addSubProperty(createProperty( "name", layer->getName()));
    layerProperties->addSubProperty(createProperty( "type", layer->getLayerTypeName()));
    layerProperties->addSubProperty(createProperty( "visible", "true"));
    layerProperties->addSubProperty(createProperty( "seed", params["seed"]));

    // now add all the remaining layer params to the subproperties
    Ogre::NameValuePairList::iterator pl;
    for(pl = params.begin(); pl != params.end(); pl++) {
        // skip common params that come first
        if(pl->first == "name" || pl->first == "type" || 
            pl->first == "visible" || pl->first == "seed") {
            continue;
        }

        // create the sub property
        QtVariantProperty* subProperty = createProperty(pl->first, pl->second);
        if(!subProperty) {
            continue;
        }

        // add this sub property parameter
        layerProperties->addSubProperty(subProperty);

        // special auto hide for color types
        if(getPropertyType(pl->first) == QVariant::Color) {
            QList<QtBrowserItem *> bi = ui->layerProperties->items(subProperty);
            ui->layerProperties->setExpanded(bi.first(),false);
        }
    }

    // done adding properties
    mRefreshing = false;

    return layerProperties;
}
//  config
//-------------------------------------------------------------------------------------
bool BaseApp::configure()
{
	Ogre::RenderSystem* rs;
	if (rs = mRoot->getRenderSystemByName(pSet->rendersystem))
	{
		mRoot->setRenderSystem(rs);
	}else{
		LogO("RenderSystem '" + pSet->rendersystem + "' is not available. Exiting.");
		return false;
	}
	if (pSet->rendersystem == "OpenGL Rendering Subsystem")  // not on dx
		mRoot->getRenderSystem()->setConfigOption("RTT Preferred Mode", pSet->buffer);

	mRoot->initialise(false);

	Uint32 flags = SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE;
	if (SDL_WasInit(flags) == 0)
	{
		SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
		if (SDL_Init(flags) != 0)
			throw std::runtime_error("Could not initialize SDL! " + std::string(SDL_GetError()));
	}
	SDL_StartTextInput();


	Ogre::NameValuePairList params;
	params.insert(std::make_pair("title", "SR Editor"));
	params.insert(std::make_pair("FSAA", toStr(pSet->fsaa)));
	params.insert(std::make_pair("vsync", pSet->vsync ? "true" : "false"));

	int pos_x = SDL_WINDOWPOS_UNDEFINED,
		pos_y = SDL_WINDOWPOS_UNDEFINED;

	/// \todo For multiple monitors, WINDOWPOS_UNDEFINED is not the best idea. Needs a setting which screen to launch on,
	/// then place the window on that screen (derive x&y pos from SDL_GetDisplayBounds)+
	/*
	if (pSet->fullscreen)
	{
		SDL_Rect display_bounds;
		if (SDL_GetDisplayBounds(settings.screen, &display_bounds) != 0)
			throw std::runtime_error("Couldn't get display bounds!");
		pos_x = display_bounds.x;
		pos_y = display_bounds.y;
	}
	*/

	//  Create window
	mSDLWindow = SDL_CreateWindow(
		"SR Editor", pos_x, pos_y, pSet->windowx, pSet->windowy,
		SDL_WINDOW_SHOWN | (pSet->fullscreen ? SDL_WINDOW_FULLSCREEN : 0) | SDL_WINDOW_RESIZABLE);

	SFO::SDLWindowHelper helper(mSDLWindow, pSet->windowx, pSet->windowy, "SR Editor", pSet->fullscreen, params);
	helper.setWindowIcon("sr-editor.png");
	mWindow = helper.getWindow();

	return true;
}
Esempio n. 8
0
	/*-----------------------------------------------------------------------------
	| Automatically restores position and orientation for free-look cameras.
	-----------------------------------------------------------------------------*/
	void Framework::restoreState(Ogre::NameValuePairList& state)
	{
		if (state.find("CameraPosition") != state.end() && state.find("CameraOrientation") != state.end())
		{
			mCameraMan->setStyle(CS_FREELOOK);
			mCamera->setPosition(Ogre::StringConverter::parseVector3(state["CameraPosition"]));
			mCamera->setOrientation(Ogre::StringConverter::parseQuaternion(state["CameraOrientation"]));
		}
	}
Esempio n. 9
0
	void OgreWidget::initialise(const Ogre::NameValuePairList *miscParams)
	{
		//These attributes are the same as those use in a QGLWidget
		setAttribute(Qt::WA_PaintOnScreen);
		setAttribute(Qt::WA_NoSystemBackground);

		//Parameters to pass to Ogre::Root::createRenderWindow()
		Ogre::NameValuePairList params;

		//If the user passed in any parameters then be sure to copy them into our own parameter set.
		//NOTE: Many of the parameters the user can supply (left, top, border, etc) will be ignored
		//as they are overridden by Qt. Some are still useful (such as FSAA).
		if(miscParams != 0)
		{
			params.insert(miscParams->begin(), miscParams->end());
		}

		//The external windows handle parameters are platform-specific
		Ogre::String externalWindowHandleParams;

		//Accept input focus
		setFocusPolicy(Qt::StrongFocus);

	#if defined(Q_WS_WIN)
		//positive integer for W32 (HWND handle) - According to Ogre Docs
		externalWindowHandleParams = Ogre::StringConverter::toString((unsigned int)(winId()));
	#endif

	#if defined(Q_WS_X11)
		//poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) for GLX - According to Ogre Docs
		QX11Info info = x11Info();
		externalWindowHandleParams  = Ogre::StringConverter::toString((unsigned long)(info.display()));
		externalWindowHandleParams += ":";
		externalWindowHandleParams += Ogre::StringConverter::toString((unsigned int)(info.screen()));
		externalWindowHandleParams += ":";
		externalWindowHandleParams += Ogre::StringConverter::toString((unsigned long)(winId()));
		//externalWindowHandleParams += ":";
		//externalWindowHandleParams += Ogre::StringConverter::toString((unsigned long)(info.visual()));
	#endif

		//Add the external window handle parameters to the existing params set.
	#if defined(Q_WS_WIN)		
		params["externalWindowHandle"] = externalWindowHandleParams;
	#endif

	#if defined(Q_WS_X11)
		params["parentWindowHandle"] = externalWindowHandleParams;
	#endif

		//Finally create our window.
		m_pOgreRenderWindow = Ogre::Root::getSingletonPtr()->createRenderWindow("OgreWindow", width(), height(), false, &params);

		mIsInitialised = true;
	}
Esempio n. 10
0
    void SceneWidget::updateOgreWindow()
    {
        if (mWindow)
        {
            Ogre::Root::getSingleton().destroyRenderTarget(mWindow);
            mWindow = NULL;
        }

        std::stringstream windowHandle;
#ifdef WIN32
        windowHandle << Ogre::StringConverter::toString((unsigned long)(this->winId()));
#else
        windowHandle << this->winId();
#endif
        std::stringstream windowTitle;
        static int count=0;
        windowTitle << ++count;

        Ogre::NameValuePairList params;

        params.insert(std::make_pair("externalWindowHandle",  windowHandle.str()));
        params.insert(std::make_pair("title", windowTitle.str()));
        params.insert(std::make_pair("FSAA", "0")); // TODO setting
        params.insert(std::make_pair("vsync", "false")); // TODO setting
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
        params.insert(std::make_pair("macAPI", "cocoa"));
        params.insert(std::make_pair("macAPICocoaUseNSView", "true"));
#endif

        mWindow = Ogre::Root::getSingleton().createRenderWindow(windowTitle.str(), this->width(), this->height(), false, &params);
        mWindow->addViewport(mCamera)->setBackgroundColour(Ogre::ColourValue(0.3,0.3,0.3,1));

        Ogre::Real aspectRatio = Ogre::Real(width()) / Ogre::Real(height());
        mCamera->setAspectRatio(aspectRatio);
    }
/** A layer property was changed in the UI. Update the layer and 
make any necessary UI changes.
@param property The changed property name
@param value The new value.
*/
void QtSpacescapeMainWindow::valueChanged(QtProperty *property, const QVariant &value)
{
    // don't update if we're refreshing
    if(mRefreshing) return;

    QList<QtProperty *> l = ui->layerProperties->properties();

    int topLevelIndex = 0;
    int layerId = -1;

    // find the layer that contains this property
    for(topLevelIndex; topLevelIndex < l.size(); topLevelIndex++) {
        if(l[topLevelIndex] == property) {
            layerId = l.size() - 1 - topLevelIndex;
            break;
        }

        bool found = false;

        QList<QtProperty *> sl = l[topLevelIndex]->subProperties();
        if(!sl.empty()) {
            for(int id = 0; id < sl.size(); id++) {
                if(sl[id] == property) {
                    layerId = l.size() - 1 - topLevelIndex;
                    found = true;
                    break;
                }
            }
        }

        if(found) break;
    }

    // did we find a valid layer id?
    std::vector<Ogre::SpacescapeLayer *> layers = ui->ogreWindow->getLayers();
    if(layerId > -1 && layerId < (int)l.size() && layerId < (int)layers.size()) {
        Ogre::NameValuePairList params;
        Ogre::String propertyStr = getProperty(property->propertyName());
        bool refresh = false;

        if(property->propertyName().indexOf("color") != -1 ||
            property->propertyName().indexOf("Color") != -1) {
            params[propertyStr] = getColor(qVariantValue<QColor>(value));
        }
        else if(propertyStr == "noiseType" || propertyStr == "maskNoiseType") {
            params[propertyStr] = value == "0" ? "fbm" : "ridged";
        }
        else if(propertyStr == "type") {
            QStringList layerTypes;
            layerTypes << "points" << "billboards" << "noise";
            params[propertyStr] = Ogre::String(layerTypes[value.toUInt()].toStdString());
            refresh = true;
        }
        else if(propertyStr == "previewTextureSize") {
            QStringList textureSizes;
            textureSizes << "64" << "128" << "256" << "512" << "1024" << "2048" << "4096" << "8192";
            params[propertyStr] = Ogre::String(textureSizes[value.toUInt()].toStdString());
        }
        else if(propertyStr == "name") {
            // set the layer name property
            ui->layerProperties->topLevelItems()[topLevelIndex]->property()->setPropertyName(value.toString());
            params[propertyStr] = Ogre::String(value.toString().toStdString());
        }
        else if(propertyStr == "destBlendFactor" || propertyStr == "sourceBlendFactor") {
            QStringList blendTypes;
            
            blendTypes << "one" << "zero" << "dest_colour" << "src_colour" 
            << "one_minus_dest_colour" << "one_minus_src_colour" 
            << "dest_alpha" << "src_alpha" << "one_minus_dest_alpha" 
            << "one_minus_src_alpha";

            params[propertyStr] = Ogre::String(blendTypes[value.toUInt()].toStdString());
        }
        else if(propertyStr == "visible") {
            ui->ogreWindow->setLayerVisible(layerId, value.toBool());
        }
        else {
            params[propertyStr] = Ogre::String(value.toString().toStdString());
        }

        // update the layer with new parameter settings
        if(!params.empty()) {
            ui->ogreWindow->updateLayer(layerId,params);
        }

        // refresh layer properties if necessary
        if(refresh) {
            // remove this layer's properties
            QList<QtBrowserItem *> bl = ui->layerProperties->topLevelItems();
            ui->layerProperties->removeProperty(bl[bl.size() - layerId - 1]->property());
            
            bl = ui->layerProperties->topLevelItems();

            // re-insert new properties
            if(!bl.empty() && layerId != bl.size()) {
                insertLayerProperties(ui->ogreWindow->getLayers()[layerId],bl[bl.size() - layerId - 1]->property(),false);
            }
            else {
                insertLayerProperties(ui->ogreWindow->getLayers()[layerId],0,false);
            }
        }
    }
}
Esempio n. 12
0
//  config
//-------------------------------------------------------------------------------------
bool BaseApp::configure()
{
	Ogre::RenderSystem* rs;
	if (rs = mRoot->getRenderSystemByName(pSet->rendersystem))
	{
		mRoot->setRenderSystem(rs);
	}else
	{	LogO("RenderSystem '" + pSet->rendersystem + "' is not available. Exiting.");
		return false;
	}
	if (pSet->rendersystem == "OpenGL Rendering Subsystem")  // not on dx
		mRoot->getRenderSystem()->setConfigOption("RTT Preferred Mode", pSet->buffer);

	mRoot->initialise(false);

	Uint32 flags = SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_HAPTIC|SDL_INIT_NOPARACHUTE;
	if (SDL_WasInit(flags) == 0)
	{
		SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
		if (SDL_Init(flags) != 0)
			throw std::runtime_error("Could not initialize SDL! " + std::string(SDL_GetError()));
	}

	//  Enable joystick events
	SDL_JoystickEventState(SDL_ENABLE);
	//  Open all available joysticks.  TODO: open them when they are required
	for (int i=0; i<SDL_NumJoysticks(); ++i)
	{
		SDL_Joystick* js = SDL_JoystickOpen(i);
		if (js)
		{
			mJoysticks.push_back(js);
			const char* s = SDL_JoystickName(js);
			int axes = SDL_JoystickNumAxes(js);
			int btns = SDL_JoystickNumButtons(js);
			//SDL_JoystickNumBalls SDL_JoystickNumHats
			LogO(Ogre::String("<Joystick> name: ")+s+"  axes: "+toStr(axes)+"  buttons: "+toStr(btns));
		}
	}
	SDL_StartTextInput();

	Ogre::NameValuePairList params;
	params.insert(std::make_pair("title", "Stunt Rally"));
	params.insert(std::make_pair("FSAA", toStr(pSet->fsaa)));
	params.insert(std::make_pair("vsync", pSet->vsync ? "true" : "false"));

	int pos_x = SDL_WINDOWPOS_UNDEFINED,
		pos_y = SDL_WINDOWPOS_UNDEFINED;

	#if 0  /// _tool_ rearrange window pos for local netw testing
	SDL_Rect screen;
	if (SDL_GetDisplayBounds(/*pSet.screen_id*/0, &screen) != 0)
		LogO("SDL_GetDisplayBounds errror");
		
	if (pSet->net_local_plr <= 0)
	{	pos_x = 0;  pos_y = 0;
	}else
	{	pos_x = screen.w - pSet->windowx;
		pos_y = screen.h - pSet->windowy;
	}
	#endif
	/// \todo For multiple monitors, WINDOWPOS_UNDEFINED is not the best idea. Needs a setting which screen to launch on,
	/// then place the window on that screen (derive x&y pos from SDL_GetDisplayBounds)


	//  Create an application window with the following settings:
	mSDLWindow = SDL_CreateWindow(
		"Stunt Rally", pos_x, pos_y, pSet->windowx, pSet->windowy,
		SDL_WINDOW_SHOWN | (pSet->fullscreen ? SDL_WINDOW_FULLSCREEN : 0) | SDL_WINDOW_RESIZABLE);

	SFO::SDLWindowHelper helper(mSDLWindow, pSet->windowx, pSet->windowy, "Stunt Rally", pSet->fullscreen, params);
	helper.setWindowIcon("stuntrally.png");
	mWindow = helper.getWindow();


	//  use this in local networking tests to render when window inactive
	/// \todo
	//if (pSet->renderNotActive)
		//mWindow->setDeactivateOnFocusChange(false);

	return true;
}
Esempio n. 13
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;
}
Esempio n. 14
0
//----------------------------------------------------------------------------------------
void MaterialEditorPrefsEditor::getPreferences(Ogre::NameValuePairList& preferences)
{
    preferences.insert(Ogre::NameValuePairList::value_type("enableSyntaxHighlighting",
        Ogre::StringConverter::toString(syntaxHighlightingCheckBox->isChecked())));
}