Ejemplo n.º 1
0
ShaderManager::GraphicsLevel ShaderManager::setGraphicsLevel(ShaderManager::GraphicsLevel newLevel)
{
  if (newLevel > mBestGraphicsLevel) {
    S_LOG_FAILURE("Cannot set graphics level " << mGraphicSchemes[newLevel]);
    return mGraphicsLevel;
  }

  S_LOG_INFO("Using graphics level " << mGraphicSchemes[newLevel]);
  Ogre::MaterialManager::getSingleton().setActiveScheme(mGraphicSchemes[newLevel]);

  Ogre::RenderWindow* window = EmberOgre::getSingleton().getRenderWindow();
  for (int i = 0; i < window->getNumViewports(); ++i) {
    window->getViewport(i)->setMaterialScheme(mGraphicSchemes[newLevel]);
  }

  switch (newLevel) {
  case LEVEL_EXPERIMENTAL:
  case LEVEL_HIGH:
    setPSSMShadows();
    break;

  case LEVEL_MEDIUM:
  case LEVEL_LOW:
  case LEVEL_DEFAULT:
    setNoShadows();
    break;
  }
  mGraphicsLevel = newLevel;

  EventLevelChanged.emit();

  return mGraphicsLevel;
}
Ejemplo n.º 2
0
    void begin()
    {
        // set-up matrices
        mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
        mRenderSystem->_setViewMatrix(Ogre::Matrix4::IDENTITY);

#if OGRE_VERSION >= MYGUI_DEFINE_VERSION(1, 7, 0) && OGRE_NO_VIEWPORT_ORIENTATIONMODE == 0
        Ogre::OrientationMode orient = mWindow->getViewport(mActiveViewport)->getOrientationMode();
        mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY * Ogre::Quaternion(Ogre::Degree(orient * 90.f), Ogre::Vector3::UNIT_Z));
#else
        mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY);
#endif

        // initialise render settings
        mRenderSystem->setLightingEnabled(false);
        mRenderSystem->_setDepthBufferParams(false, false);
        mRenderSystem->_setDepthBias(0, 0);
        mRenderSystem->_setCullingMode(Ogre::CULL_NONE);
        mRenderSystem->_setFog(Ogre::FOG_NONE);
        mRenderSystem->_setColourBufferWriteEnabled(true, true, true, true);
        mRenderSystem->unbindGpuProgram(Ogre::GPT_FRAGMENT_PROGRAM);
        mRenderSystem->unbindGpuProgram(Ogre::GPT_VERTEX_PROGRAM);
        mRenderSystem->setShadingType(Ogre::SO_GOURAUD);

        // initialise texture settings
        mRenderSystem->_setTextureCoordCalculation(0, Ogre::TEXCALC_NONE);
        mRenderSystem->_setTextureCoordSet(0, 0);
        mRenderSystem->_setTextureUnitFiltering(0, Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_NONE);
        mRenderSystem->_setTextureAddressingMode(0, mTextureAddressMode);
        mRenderSystem->_setTextureMatrix(0, Ogre::Matrix4::IDENTITY);
#if OGRE_VERSION < MYGUI_DEFINE_VERSION(1, 6, 0)
        mRenderSystem->_setAlphaRejectSettings(Ogre::CMPF_ALWAYS_PASS, 0);
#else
        mRenderSystem->_setAlphaRejectSettings(Ogre::CMPF_ALWAYS_PASS, 0, false);
#endif
        mRenderSystem->_setTextureBlendMode(0, mColorBlendMode);
        mRenderSystem->_setTextureBlendMode(0, mAlphaBlendMode);
        mRenderSystem->_disableTextureUnitsFrom(1);

        // enable alpha blending
        mRenderSystem->_setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);

        // always use wireframe
        // TODO: add option to enable wireframe mode in platform
        mRenderSystem->_setPolygonMode(Ogre::PM_SOLID);
    }
Ejemplo n.º 3
0
 bool MagicListener::mouseMoved( const OIS::MouseEvent &arg )
 {
     Ogre::RenderWindow* rw = RenderSystem::Get()->GetRenderWindow();
     if (arg.state.X.abs < rw->getViewport(0)->getActualLeft() + 1
         || arg.state.Y.abs < rw->getViewport(0)->getActualTop() + 1
         || arg.state.X.abs > rw->getViewport(0)->getActualLeft() + rw->getViewport(0)->getActualWidth()
         || arg.state.Y.abs > rw->getViewport(0)->getActualTop() + rw->getViewport(0)->getActualHeight())
     {
         return true;
     }
     ToolKit::Get()->SetMousePressLocked(false);
     MyGUI::InputManager::getInstance().injectMouseMove(arg.state.X.abs, arg.state.Y.abs, arg.state.Z.abs);
     return MagicApp::AppManager::Get()->MouseMoved(arg); 
 }
Ejemplo n.º 4
0
    void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation)
    {
        Gui* gui = Gui::getInstancePtr();
        if (gui == nullptr)
            return;

        if (Ogre::RENDER_QUEUE_OVERLAY != queueGroupId)
            return;

        Ogre::Viewport* viewport = mSceneManager->getCurrentViewport();
        if (nullptr == viewport
                || !viewport->getOverlaysEnabled())
            return;

        if (mWindow->getNumViewports() <= mActiveViewport
                || viewport != mWindow->getViewport(mActiveViewport))
            return;

        mCountBatch = 0;

        static Timer timer;
        static unsigned long last_time = timer.getMilliseconds();
        unsigned long now_time = timer.getMilliseconds();
        unsigned long time = now_time - last_time;

        onFrameEvent((float)((double)(time) / (double)1000));

        last_time = now_time;

        //begin();
        setManualRender(true);
        onRenderToTarget(this, mUpdate);
        //end();

        // сбрасываем флаг
        mUpdate = false;
    }
Ejemplo n.º 5
0
 bool MagicListener::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
 {
     Ogre::RenderWindow* rw = RenderSystem::Get()->GetRenderWindow();
     if (arg.state.X.abs < rw->getViewport(0)->getActualLeft() + 1
         || arg.state.Y.abs < rw->getViewport(0)->getActualTop() + 1
         || arg.state.X.abs > rw->getViewport(0)->getActualLeft() + rw->getViewport(0)->getActualWidth()
         || arg.state.Y.abs > rw->getViewport(0)->getActualTop() + rw->getViewport(0)->getActualHeight())
     {
         return true;
     }
     else
     {
         if (ToolKit::Get()->IsMousePressLocked() == false)
         {
             MyGUI::InputManager::getInstance().injectMousePress(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id));
         }            
         return MagicApp::AppManager::Get()->MousePressed(arg, id);
     }
 }
Ejemplo n.º 6
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#else
int main (int argc, char *argv[]) {
#endif

	Ogre::Root *ogre;
	Ogre::RenderWindow *window;
	Ogre::SceneManager *sceneMgr;
	Ogre::SceneManager *guiSceneMgr;
	Ogre::Camera *camera;
	Ogre::Camera *guiCamera;

	// fire up an Ogre rendering window. Clearing the first two (of three) params will let us 
	// specify plugins and resources in code instead of via text file
	ogre = new Ogre::Root("", "");

#if defined(_DEBUG)
	ogre->loadPlugin("RenderSystem_GL_d");
#else
	ogre->loadPlugin("RenderSystem_GL");
#endif

	Ogre::RenderSystemList *renderSystems = NULL;
	Ogre::RenderSystemList::iterator r_it;

	renderSystems = ogre->getAvailableRenderers();
	r_it = renderSystems->begin();
	ogre->setRenderSystem(*r_it);
	ogre->initialise(false);

	// load common plugins
#if defined(_DEBUG)
	//ogre->loadPlugin("Plugin_CgProgramManager_d");		
	ogre->loadPlugin("Plugin_OctreeSceneManager_d");
#else
	//ogre->loadPlugin("Plugin_CgProgramManager");		
	ogre->loadPlugin("Plugin_OctreeSceneManager");
#endif
	// load the basic resource location(s)
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource", "FileSystem", "General");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource/gui.zip", "Zip", "GUI");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation("meshes", "FileSystem", "Meshes");
#if defined(WIN32)
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation("c:\\windows\\fonts", "FileSystem", "GUI");
#endif

	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("GUI");
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Meshes");

	// setup main window; hardcode some defaults for the sake of presentation
	Ogre::NameValuePairList opts;
	opts["resolution"] = "1024x768";
	opts["fullscreen"] = "false";
	opts["vsync"] = "false";

	// create a rendering window with the title "CDK"
	window = ogre->createRenderWindow("Bouwgame Client v0.1", 1024, 768, false, &opts);

	// since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article 
	// we'll see how to change this
	sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);
	guiSceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);

	guiCamera = guiSceneMgr->createCamera("GUICamera");
	guiCamera->setNearClipDistance(5);
	camera = sceneMgr->createCamera("camera");
	camera->setNearClipDistance(5);
    Ogre::Viewport* vp = window->addViewport(guiCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0.2f,0.2f,0.8f));

	/* ambient light */
	sceneMgr->setAmbientLight(Ogre::ColourValue(0.8, 0.8, 0.8));
	sceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);

	/* meshes */
	Ogre::Entity* ent = sceneMgr->createEntity( "BouwPlaatsEntity", "world.mesh" );
	Ogre::SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode("BouwNode", Ogre::Vector3(0, 0, 0));
    node->attachObject(ent);
	//node->setScale(Ogre::Vector3(0.7,0.7,0.7));

	ent = sceneMgr->createEntity("plaats", "bouwplaats_step_00.mesh");
	Ogre::Vector3 size = ent->getBoundingBox().getSize();
	Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats size: ") + Ogre::StringConverter::toString(size));
	size = ent->getBoundingBox().getMaximum();
	Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats max: ") + Ogre::StringConverter::toString(size));
	size = ent->getBoundingBox().getMinimum();
	Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats min: ") + Ogre::StringConverter::toString(size));

    Ogre::Entity* ent1 = sceneMgr->createEntity( "KeetEntity", "keet.mesh" );
	Ogre::SceneNode* scenenode = sceneMgr->getRootSceneNode()->createChildSceneNode("KeetNode", Ogre::Vector3(0, 0, 0));
    scenenode->attachObject(ent1);

	
	Ogre::Entity* ent2 = sceneMgr->createEntity( "HekjeEntity", "hekje.mesh" );
	Ogre::SceneNode* scenenode2 = sceneMgr->getRootSceneNode()->createChildSceneNode("HekjeNode", Ogre::Vector3(0, -100, 0));
    scenenode2->attachObject(ent2);
	scenenode2->setScale(Ogre::Vector3(400,0,100));

	// most examples get the viewport size to calculate this; for now, we'll just 
	// set it to 4:3 the easy way
	camera->setAspectRatio((Ogre::Real)1.333333);
	camera->setPosition(Ogre::Vector3(40,100,10));
	guiCamera->setPosition(0, 0, 300);
	guiCamera->lookAt(node->getPosition());

	// this next bit is for the sake of the input handler
	unsigned long hWnd;
	window->getCustomAttribute("WINDOW", &hWnd);

	
	// set up the input handlers
	Simulation *sim = new Simulation();
	InputHandler *handler = new InputHandler(sim, hWnd, camera);
	DataManager *dataManager = new DataManager();
	GameAI* gameAI = new GameAI(dataManager);

	//Create Network
	Network * net = new Network(dataManager);
	//net->start();

	sim->requestStateChange(GUI);
	gui = new GuiManager();

	// networkshit
	while(!net->isConnected())
	{
		Sleep(1000);
	}
	net->Send(GETGROUPS, "", "", NULL);
	net->Send(LOGIN, "gast", "gast", 1);

	gui->setSimulation(sim);
	gui->init("", ogre, guiSceneMgr, window);
	gui->activate("main");
	handler->setWindowExtents(1024,768);
	
	SimulationState cState;
	Ogre::WindowEventUtilities::addWindowEventListener(window, handler);

	DWORD tFrameStart = 0x0; //in miliseconds
	signed long tFrameX = 0x0;
	float tDelta2 = 0.0f; //in seconds
	float m_fps = 60.0f;
	tFrameStart = GetTickCount();

	float tDelta;

	//testAI->calculateNextPath(40,10);

	while ((cState = sim->getCurrentState()) != SHUTDOWN) {

		tFrameX = GetTickCount() - tFrameStart;
		tDelta2 = (float)tFrameX / 1000.0f;
		if (tDelta2 > 3600) // tDelta > 1 hour
			tDelta2 = 1.0f / m_fps; //< System tick count has highly likely overflowed, so get approximation
		tFrameStart = GetTickCount();
		m_fps = (int)(1.0f / tDelta2);

		tDelta = tDelta2;

		handler->capture();
		handler->update(tDelta);
		gui->update(tDelta);

		//if (sim->getCurrentState() == SIMULATION || sim->getCurrentState() == SIMULATION_MOUSELOOK)
//			testAI->update(tDelta);

		// run the message pump (Eihort)
		Ogre::WindowEventUtilities::messagePump();

		ogre->renderOneFrame();

		if (sim->getCurrentState() != cState) {
			handler->StateSwitched(cState, sim->getCurrentState());
			switch (sim->getCurrentState()) {
				case GUI:
					window->getViewport(0)->setCamera(guiCamera);
					break;
				case SIMULATION:
					window->getViewport(0)->setCamera(camera);
					break;
			}
		}

	}

	// clean up after ourselves
	//delete testAI;
	delete sim;
	delete ogre;
	delete handler;
	delete gameAI;
	delete dataManager;

	return 0;
}