Ejemplo n.º 1
0
    //---------------------------------------------------------------------
    String GpuProgramManager::addRenderSystemToName( const String & name )
    {
        // Use the current render system
        RenderSystem* rs = Root::getSingleton().getRenderSystem();

        return rs->getName() + "_" + name;
    }
//-----------------------------------------------------------------------------
void FFPRenderStateBuilder::buildRenderState(ShaderGenerator::SGPass* sgPass, TargetRenderState* renderState)
{
    renderState->reset();

    // Build transformation sub state.
    buildFFPSubRenderState(FFP_TRANSFORM, FFPTransform::Type, sgPass, renderState); 

    // Build colour sub state.
    buildFFPSubRenderState(FFP_COLOUR, FFPColour::Type, sgPass, renderState);

    // Build lighting sub state.
    buildFFPSubRenderState(FFP_LIGHTING, FFPLighting::Type, sgPass, renderState);

    // Build texturing sub state.
    buildFFPSubRenderState(FFP_TEXTURING, FFPTexturing::Type, sgPass, renderState); 
    
    // Build fog sub state.
    buildFFPSubRenderState(FFP_FOG, FFPFog::Type, sgPass, renderState);
	
	RenderSystem* rs = Root::getSingleton().getRenderSystem();
	if (rs->getName().find("Direct3D11") != String::npos && 
		sgPass->getSrcPass()->getAlphaRejectFunction() != CMPF_ALWAYS_PASS)
	{
		buildFFPSubRenderState(FFP_ALPHA_TEST, FFPAlphaTest::Type, sgPass, renderState);
	}
	
    // Resolve colour stage flags.
    resolveColourStageFlags(sgPass, renderState);

}
Ejemplo n.º 3
0
    //-----------------------------------------------------------------------
    void Root::saveConfig(void)
    {
        if (mConfigFileName.empty ())
            return;

		std::ofstream of(mConfigFileName.c_str());

        if (!of)
            OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE, "Cannot create settings file.",
            "Root::saveConfig");

        if (mActiveRenderer)
        {
            of << "Render System=" << mActiveRenderer->getName() << std::endl;
        }
        else
        {
            of << "Render System=" << std::endl;
        }

        for (RenderSystemList::const_iterator pRend = getAvailableRenderers()->begin(); pRend != getAvailableRenderers()->end(); ++pRend)
        {
            RenderSystem* rs = *pRend;
            of << std::endl;
            of << "[" << rs->getName() << "]" << std::endl;
            const ConfigOptionMap& opts = rs->getConfigOptions();
            for (ConfigOptionMap::const_iterator pOpt = opts.begin(); pOpt != opts.end(); ++pOpt)
            {
				of << pOpt->first << "=" << pOpt->second.currentValue << std::endl;
            }
        }

        of.close();

    }
Ejemplo n.º 4
0
void OgreRenderer::configure(const std::string &logPath,
                            const std::string& renderSystem,
                             const std::string& rttMode
                            )
{
    mOgreInit = new OgreInit::OgreInit();
    mRoot = mOgreInit->init(logPath + "/ogre.log");

    RenderSystem* rs = mRoot->getRenderSystemByName(renderSystem);
    if (rs == 0)
        throw std::runtime_error ("RenderSystem with name " + renderSystem + " not found, make sure the plugins are loaded");
    mRoot->setRenderSystem(rs);

    if (rs->getName().find("OpenGL") != std::string::npos)
        rs->setConfigOption ("RTT Preferred Mode", rttMode);
}
Ejemplo n.º 5
0
/* 
* Initialization Methods
*/
void Application::setupWindowRendererSystem(void) {

	mResourcesCfg = "resources.cfg";
	mPluginsCfg = "plugins.cfg";

	NameValuePairList params;
	// Initialization
	mRoot = new Root(mPluginsCfg);

	setupResources();

	// load plugins
#ifdef _WIN32
	mRoot->loadPlugin("RenderSystem_GL_d");
	mRoot->loadPlugin("Plugin_ParticleFX_d");
#endif
#ifdef __linux__
	mRoot->loadPlugin("/lusr/opt/ogre-1.9/lib/OGRE/RenderSystem_GL");
#endif

	// Select render system
	const RenderSystemList &renderers = mRoot->getAvailableRenderers();
	RenderSystem * renderSystem = nullptr;
	LogManager::getSingletonPtr()->logMessage("Getting available renderers");
	for (auto renderer = renderers.begin(); renderer != renderers.end(); renderer++)
	{
		String name = (*renderer)->getName();
		LogManager::getSingletonPtr()->logMessage(name);
		renderSystem = *renderer;
	}
	if (renderSystem)
	{
		LogManager::getSingletonPtr()->logMessage("Using renderer " + renderSystem->getName());
		mRoot->setRenderSystem(renderSystem);
	}
	else
	{
		LogManager::getSingletonPtr()->logMessage(LML_CRITICAL, "Initializing render system failed. No renderers available.");
	}

	// Initialize with render system, no new window (yet)
	mRoot->initialise(false);

	// Create scene manager, render window, and camera
	mSceneManager = mRoot->createSceneManager(ST_GENERIC);
	mRenderWindow = mRoot->createRenderWindow(PROJECT_NAME, width = 1200, height = 900, false, &params);
}
Ejemplo n.º 6
0
    //-----------------------------------------------------------------------
    RenderSystem* Root::getRenderSystemByName(const String& name)
    {
        if (name.empty())
        {
            // No render system
            return NULL;
        }

        RenderSystemList::const_iterator pRend;
        for (pRend = getAvailableRenderers()->begin(); pRend != getAvailableRenderers()->end(); ++pRend)
        {
            RenderSystem* rs = *pRend;
            if (rs->getName() == name)
                return rs;
        }

        // Unrecognised render system
        return NULL;
    }
Ejemplo n.º 7
0
void OgreRenderer::configure(const std::string &logPath,
                            const std::string& renderSystem,
                             const std::string& rttMode,
                            bool _logging)
{
    // Set up logging first
    new LogManager;
    Log *log = LogManager::getSingleton().createLog(logPath + std::string("Ogre.log"));
    logging = _logging;

    if(logging)
        // Full log detail
        log->setLogDetail(LL_BOREME);
    else
        // Disable logging
        log->setDebugOutputEnabled(false);

#if defined(__APPLE__) && !defined(__LP64__)
    mRoot = new CustomRoot("", "", "");
#else
    mRoot = new Root("", "", "");
#endif

    #if defined(ENABLE_PLUGIN_GL) || defined(ENABLE_PLUGIN_Direct3D9) || defined(ENABLE_PLUGIN_CgProgramManager) || defined(ENABLE_PLUGIN_OctreeSceneManager) || defined(ENABLE_PLUGIN_ParticleFX)
    loadPlugins();
    #endif

    std::string pluginDir;
    const char* pluginEnv = getenv("OPENMW_OGRE_PLUGIN_DIR");
    if (pluginEnv)
        pluginDir = pluginEnv;
    else
    {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        pluginDir = ".\\";
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
        pluginDir = OGRE_PLUGIN_DIR;
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
        pluginDir = OGRE_PLUGIN_DIR_REL;
#endif
    }

    boost::filesystem::path absPluginPath = boost::filesystem::absolute(boost::filesystem::path(pluginDir));

    pluginDir = absPluginPath.string();

    Files::loadOgrePlugin(pluginDir, "RenderSystem_GL", *mRoot);
    Files::loadOgrePlugin(pluginDir, "RenderSystem_GL3Plus", *mRoot);
    Files::loadOgrePlugin(pluginDir, "RenderSystem_Direct3D9", *mRoot);
    Files::loadOgrePlugin(pluginDir, "Plugin_CgProgramManager", *mRoot);

    RenderSystem* rs = mRoot->getRenderSystemByName(renderSystem);
    if (rs == 0)
        throw std::runtime_error ("RenderSystem with name " + renderSystem + " not found, make sure the plugins are loaded");
    mRoot->setRenderSystem(rs);

    if (rs->getName().find("OpenGL") != std::string::npos)
        rs->setConfigOption ("RTT Preferred Mode", rttMode);
}
bool GLXConfigurator::CreateWindow() {


	const char *bla[] = {"Rendering Settings", "-bg", "honeydew3", "-fg", "black","-bd","darkseagreen4"};
	int argc = sizeof(bla)/sizeof(*bla);

	toplevel = XtVaOpenApplication(&appContext, "OGRE", NULL, 0, &argc, const_cast<char**>(bla), NULL,sessionShellWidgetClass,
		XtNwidth, mWidth,
		XtNheight, mHeight,
		XtNminWidth, mWidth,
		XtNmaxWidth, mWidth,
		XtNminHeight, mHeight,
		XtNmaxHeight, mHeight,
		XtNallowShellResize, False,
		XtNborderWidth, 0,
		XtNoverrideRedirect, False,
		NULL, NULL);

	/* Find out display and screen used */
	mDisplay = XtDisplay(toplevel);
	int screen = DefaultScreen(mDisplay);
	Window rootWindow = RootWindow(mDisplay,screen);

	/* Move to center of display */
	int w = DisplayWidth(mDisplay, screen);
	int h = DisplayHeight(mDisplay, screen);
	XtVaSetValues(toplevel,
			XtNx, w/2-mWidth/2,
			XtNy, h/2-mHeight/2, 0, NULL);

	/* Backdrop stuff */
	mBackDrop = CreateBackdrop(rootWindow, DefaultDepth(mDisplay,screen));

	/* Create toplevel */
	box = XtVaCreateManagedWidget("box",formWidgetClass,toplevel,
		XtNbackgroundPixmap, mBackDrop,
		0,NULL);

	/* Create renderer selection */
	int cury = ystart + 0*rowh;

	Widget lb1 = XtVaCreateManagedWidget("topLabel", labelWidgetClass, box, XtNlabel, "Select Renderer", XtNborderWidth, 0,
		XtNwidth, col1w, 	// Fixed width
		XtNheight, 18,
		XtNleft, XawChainLeft,
		XtNtop, XawChainTop,
		XtNright, XawChainLeft,
		XtNbottom, XawChainTop,
		XtNhorizDistance, col1x,
		XtNvertDistance, cury,
		XtNjustify, XtJustifyLeft,
		NULL);
	const char *curRenderName = " Select One "; // Name of current renderer, or hint to select one
	if(mRenderer)
		curRenderName = mRenderer->getName().c_str();
	Widget mb1 = XtVaCreateManagedWidget("Menu", menuButtonWidgetClass, box, XtNlabel,curRenderName,
		XtNresize, false,
		XtNresizable, false,
		XtNwidth, col2w, 	// Fixed width
		XtNheight, 18,
		XtNleft, XawChainLeft,
		XtNtop, XawChainTop,
		XtNright, XawChainLeft,
		XtNbottom, XawChainTop,
		XtNhorizDistance, col2x,
		XtNvertDistance, cury,
		NULL);

	Widget menu = XtVaCreatePopupShell("menu", simpleMenuWidgetClass, mb1,
		0, NULL);

	const RenderSystemList& renderers = Root::getSingleton().getAvailableRenderers();
	for (RenderSystemList::const_iterator pRend = renderers.begin();
	                pRend != renderers.end(); pRend++) {
		// Create callback data
		mRendererCallbackData.push_back(RendererCallbackData(this, *pRend, mb1));

		Widget entry = XtVaCreateManagedWidget("menuentry", smeBSBObjectClass, menu,
			XtNlabel, (*pRend)->getName().c_str(),
			0, NULL);
		XtAddCallback(entry, XtNcallback, (XtCallbackProc)&GLXConfigurator::renderSystemHandler, &mRendererCallbackData.back());
	}

	Widget bottomPanel = XtVaCreateManagedWidget("bottomPanel", formWidgetClass, box,
		XtNsensitive, True,
		XtNborderWidth, 0,
		XtNwidth, 150, 	// Fixed width
		XtNleft, XawChainLeft,
		XtNtop, XawChainTop,
		XtNright, XawChainLeft,
		XtNbottom, XawChainTop,
		XtNhorizDistance, mWidth - 160,
		XtNvertDistance, mHeight - 40,
		NULL);

	Widget helloButton = XtVaCreateManagedWidget("cancelButton", commandWidgetClass, bottomPanel, XtNlabel," Cancel ", NULL);
	XtAddCallback(helloButton, XtNcallback, (XtCallbackProc)&GLXConfigurator::cancelHandler, this);

	Widget exitButton = XtVaCreateManagedWidget("acceptButton", commandWidgetClass, bottomPanel, XtNlabel," Accept ", XtNfromHoriz,helloButton, NULL);
 	XtAddCallback(exitButton, XtNcallback, (XtCallbackProc)&GLXConfigurator::acceptHandler, this);

	XtRealizeWidget(toplevel);

	if(mRenderer)
		/* There was already a renderer selected; display its options */
		SetRenderer(mRenderer);

	return true;
}
bool OgreFramework::initOgre(Ogre::String wndTitle, OIS::KeyListener *pKeyListener, OIS::MouseListener *pMouseListener)
{
    Ogre::LogManager* logMgr = new Ogre::LogManager();

    m_pLog = Ogre::LogManager::getSingleton().createLog("OgreLogfile.log", true, true, false);
    m_pLog->setDebugOutputEnabled(true);

    m_pRoot = new Ogre::Root();

    
    /*if(!m_pRoot->showConfigDialog())
        return false;*/
    
    
    //MY EDIT - auto renderer select
    //std::cout<<"myedit\n\n";
    
    #if defined(_DEBUG)
    ogre->loadPlugin("RenderSystem_GL_d");
#else
    m_pRoot->loadPlugin("RenderSystem_GL");
    //m_pRoot->loadPlugin("Plugin_CgProgramManager");
#endif
    
    RenderSystem *renderSystem;
    bool ok = false;
    RenderSystemList renderers =
        m_pRoot->getAvailableRenderers();
    //std::cout<<"myedit2\n\n";

    // See if the list is empty (no renderers available)
    if(renderers.empty())
        std::cout<<"Houston we've got a problem!\n\n";//TODO do something please...

    for(RenderSystemList::iterator it = renderers.begin();
        it != renderers.end(); it++)
    {
        renderSystem = (*it);
        if(strstr((renderSystem->getName().c_str()), "OpenGL"))
        {
            ok = true;
            break;
        }
    }

    if(!ok) {
        // We still don't have a renderer; pick
        // up the first one from the list
        renderSystem = (*renderers.begin());
    }

    m_pRoot->setRenderSystem(renderSystem);

    // Manually set some configuration options (optional)
    //renderSystem->setConfigOption("Video Mode", "800 x 600");
    //std::cout<<"myedit - end\n\n";
    //END of My edit
    
    
    m_pRenderWnd = m_pRoot->initialise(true, wndTitle);

    m_pSceneMgr = m_pRoot->createSceneManager(ST_GENERIC, "SceneManager");
    m_pSceneMgr->setAmbientLight(Ogre::ColourValue(0.7f, 0.7f, 0.7f));

    m_pCamera = m_pSceneMgr->createCamera("Camera");
    //m_pCamera->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
    m_pCamera->setPosition(Vector3(0.1, 100, 0.1));
    //m_pCamera->lookAt(Vector3(0.1, 0.1, 0.1));
    //m_pCamera->setDirection(0,-1,0);
    m_pCamera->setNearClipDistance(1);
    //m_pCamera->setFixedYawAxis(false);
    m_pCamera->setOrientation(Ogre::Quaternion(0.7071067811865475244,-0.7071067811865475244,0.0,0.0));// Square root of 1/2
    m_pViewport = m_pRenderWnd->addViewport(m_pCamera);
    
    m_pViewport->setBackgroundColour(ColourValue(0.8f, 0.7f, 0.6f, 1.0f));

    m_pCamera->setAspectRatio(Real(m_pViewport->getActualWidth()) / Real(m_pViewport->getActualHeight()));

    m_pViewport->setCamera(m_pCamera);

    size_t hWnd = 0;
    OIS::ParamList paramList;
    m_pRenderWnd->getCustomAttribute("WINDOW", &hWnd);

    paramList.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(hWnd)));

    m_pInputMgr = OIS::InputManager::createInputSystem(paramList);

    m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject(OIS::OISKeyboard, true));
    m_pMouse = static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject(OIS::OISMouse, true));

    m_pMouse->getMouseState().height = m_pRenderWnd->getHeight();
    m_pMouse->getMouseState().width      = m_pRenderWnd->getWidth();

    if(pKeyListener == 0)
        m_pKeyboard->setEventCallback(this);
    else
        m_pKeyboard->setEventCallback(pKeyListener);

    if(pMouseListener == 0)
        m_pMouse->setEventCallback(this);
    else
        m_pMouse->setEventCallback(pMouseListener);

    Ogre::String secName, typeName, archName;
    Ogre::ConfigFile cf;
    cf.load("resources.cfg");

    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
        }
    }
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    m_pTimer = new Ogre::Timer();
    m_pTimer->reset();

    m_pTrayMgr = new OgreBites::SdkTrayManager("TrayMgr", m_pRenderWnd, m_pMouse, this);
    m_pTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
    Ogre::FontManager::getSingleton().getByName("SdkTrays/Caption")->load();
    //m_pTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);//a na co mi to?
    m_pTrayMgr->hideCursor();
    caption = m_pTrayMgr->createLabel(OgreBites::TL_TOPLEFT,"caption","Loading...",1280);
    m_pRenderWnd->setActive(true);

    return true;
}