Пример #1
0
    IntroState::IntroState(Engine* p_engine) :
        GameState(p_engine),
        m_totalMilliseconds(std::time_t(2000)),
        m_elapsedMilliseconds(0)
    {
        std::clog << "Entering intro state..." << std::endl;

        // do one input state capture just to hide the mouse cursor
        InputSystem* inputSystem = m_engine->getInputSystem();
        inputSystem->capture();

        // get the material by name
        std::clog << "Loading fade overlay material..." << std::endl;
        Ogre::ResourcePtr resptr = Ogre::MaterialManager::getSingleton().
            getByName("Materials/FadeOverlay");
        Ogre::Material* material = dynamic_cast<Ogre::Material*>(resptr.getPointer());
        Ogre::Technique* tech = material->getTechnique(0);
        Ogre::Pass* pass = tech->getPass(0);

        m_textureUnitState = pass->getTextureUnitState(0);

        // get the overlay
        std::clog << "Loading fade overlay..." << std::endl;
        m_fadeOverlay = Ogre::OverlayManager::getSingleton().getByName("Overlays/FadeOverlay");

        m_alpha = 1.0;
        m_fadeOverlay->show();
    }
Пример #2
0
 void Homepage::SwitchDisplayMode()
 {
     mDisplayMode++;
     if (mDisplayMode > 2)
     {
         mDisplayMode = 0;
     }
     if (mDisplayMode == 0)
     {
         MagicCore::RenderSystem::Get()->GetMainCamera()->setPolygonMode(Ogre::PolygonMode::PM_SOLID);
     }
     else if (mDisplayMode == 1)
     {
         MagicCore::RenderSystem::Get()->GetMainCamera()->setPolygonMode(Ogre::PolygonMode::PM_WIREFRAME);
     }
     else if (mDisplayMode == 2)
     {
         MagicCore::RenderSystem::Get()->GetMainCamera()->setPolygonMode(Ogre::PolygonMode::PM_POINTS);
     }
     Ogre::Material* material = dynamic_cast<Ogre::Material*>(Ogre::MaterialManager::getSingleton().getByName("CookTorrance").getPointer());
     if (material)
     {
         if (mDisplayMode == 0)
         {
             material->setCullingMode(Ogre::CullingMode::CULL_NONE);
         }
         else
         {
             material->setCullingMode(Ogre::CullingMode::CULL_CLOCKWISE);
         }
     }
     UpdateModelRendering();
 }
Пример #3
0
HTML::~HTML()
{
  // remove material and texture so they won't keep any space in memory
  if(materialName != "")
  {
    Ogre::Material* mat = (Ogre::Material*)Ogre::MaterialManager::getSingleton().getByName(materialName).get();
    mat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
    Ogre::TextureManager::getSingleton().remove(texture->getName());
  }

  if(window)
    window->destroy();
}
Пример #4
0
RenderedTexture::RenderedTexture(Ogre::Entity* entity,
                                 Ogre::SceneManager* sceneMgr,
                                 Ogre::uint8 renderQueueGroup) :
    sceneMgr(sceneMgr),
    entity(entity),
    entityKey(generateEntityKey(entity)),
    renderQueueGroup(renderQueueGroup)
{
    //Add self to list of RenderedTexture's
    typedef std::pair<std::string, RenderedTexture*> ListItem;
    selfList.insert(ListItem(entityKey, this));

    // TODO: use bounding sphere
    //Note - this radius calculation assumes the object is somewhat rounded (like trees/rocks/etc.)
    Ogre::Real tmp;
    Ogre::AxisAlignedBox boundingBox = entity->getBoundingBox();
    entityRadius = boundingBox.getMaximum().x - boundingBox.getCenter().x;
    tmp = boundingBox.getMaximum().y - boundingBox.getCenter().y;
    if (tmp > entityRadius)
        entityRadius = tmp;
    tmp = boundingBox.getMaximum().z - boundingBox.getCenter().z;
    if (tmp > entityRadius)
        entityRadius = tmp;

    entityCenter = boundingBox.getCenter();

    //Render impostor textures
    renderTextures();

    //Set up material
    material =
        Ogre::MaterialManager::getSingleton().create(
            getUniqueID("RenderedEntityMaterial"), "EntityRenderer");

    Ogre::Material* m = material.getPointer();
    Ogre::Pass* p = m->getTechnique(0)->getPass(0);

    p->createTextureUnitState(texture->getName());

    p->setLightingEnabled(false);
    m->setReceiveShadows(false);

    if (blendMode == ALPHA_REJECT_IMPOSTOR){
        p->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 128);
        //p->setAlphaRejectSettings(CMPF_GREATER_EQUAL, 64);
    } else if (blendMode == ALPHA_BLEND_IMPOSTOR){
        p->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);
        p->setDepthWriteEnabled(false);  
    }
}
Пример #5
0
//-------------------------------------------------------
void Ground::LoadFromHeightMap(std::shared_ptr<Ogre::Image> hmap, Ogre::SceneNode* parentNode)
{
    mImage = hmap;
    Ogre::Box box = Ogre::Box(0, 0, mImage->getWidth(), mImage->getHeight());

    mRootNode = parentNode->createChildSceneNode();
    
    mGlobalBoundingBox.setNull();

    Ogre::Material* groundMaterial = CreateGroundMaterialTextured("Material/" + CLASS_NAME + "/Textured", mImage.get());
    
    static const float VERTEX_STEP = 1.0f;
    static const float HEIGHT_STEP = 8.0f;

    float offsetX = GROUND_SIZE * VERTEX_STEP / 2.0f;
    float offsetY = GROUND_SIZE * VERTEX_STEP / 2.0f;

    size_t width  = mImage->getWidth();
    size_t height = mImage->getHeight();

    float texStep = 1.0f / REGIONS_NUMBER;

    size_t texRegionWidth  = static_cast<size_t>(std::ceil(static_cast<float>(width) / REGIONS_NUMBER));
    size_t texRegionHeight = static_cast<size_t>(std::ceil(static_cast<float>(height) / REGIONS_NUMBER));
    for (size_t y = 0; y < REGIONS_NUMBER; ++y)
    {
        size_t top = y * texRegionHeight;
        for (size_t x = 0; x < REGIONS_NUMBER; ++x)
        {
            size_t left = x * texRegionWidth;
            Ogre::Box roi = Ogre::Box(left, height - std::min(top + texRegionHeight + 1, height), std::min(left + texRegionWidth + 1, width), height - top);
                
            Ogre::MeshPtr mesh = CreateRegion(y * REGIONS_NUMBER + x, groundMaterial->getName(), roi,
                Ogre::Vector3(x * VERTEX_STEP * REGION_SIZE - offsetX, y * VERTEX_STEP * REGION_SIZE - offsetY, 0.0f),
                Ogre::Vector3(VERTEX_STEP, VERTEX_STEP, HEIGHT_STEP),
                Ogre::Vector2(x * texStep, 1.0f - (y + 1) * texStep));

            Ogre::Entity* entity = mSceneManager->createEntity(mesh);
            
            auto node = mRootNode->createChildSceneNode();
            node->attachObject(entity);
            node->showBoundingBox(true);

            mGlobalBoundingBox.merge(entity->getBoundingBox());

            mEntities.push_back(entity);
        }
    }
}
void MovableTextOverlayAttributes::setMaterialName(const Ogre::String & materialName)
{
	if (mMaterialName != materialName)
	{
		if (mMaterialName.length())
			Ogre::MaterialManager::getSingletonPtr()->getByName(mMaterialName).getPointer()->unload();

		mMaterialName = materialName;
		if (mMaterialName.length())
		{
			Ogre::Material *mpMaterial = dynamic_cast<Ogre::Material*>(Ogre::MaterialManager::getSingletonPtr()->getByName(mMaterialName).getPointer());
			if (!mpMaterial)
				Ogre::Exception(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Could not find font " + materialName, "MovableTextOverlay::setMaterialName");
			mpMaterial->load();
		}
	}
}
Пример #7
0
void ParticleEffect::Initialize(Ogre::SceneManager *sceneManager, Ogre::SceneNode* parentNode, Ogre::String object_name, Ogre::String material_name, PhysicsEngine &physicsEngine, unsigned int parentID)
{
	PhysicsEntity::Initialize(sceneManager, parentNode, physicsEngine, parentID);
	bodyType = ENTITY_BODY_METAPHYSICAL;

	 Ogre::Entity* entity = sceneManager->createEntity(object_name);

	/* Apply a material to the entity */
	materialName = material_name + std::to_string(objectID);
	Ogre::MaterialPtr origMat = Ogre::MaterialManager::getSingleton().getByName(material_name);
	Ogre::Material* mat = origMat.get();
	mat->clone(materialName);
	entity->setMaterialName(materialName);

	sceneNode->attachObject(entity);
	sceneNode->translate(0,0,0);
	
}
Пример #8
0
 Fader::Fader(const char *OverlayName, const char *MaterialName, FaderCallback *instance)
 {
     _fadeop = FADE_NONE;
     _alpha = 0.0;
     _inst = instance;

     // Get the material by name
     Ogre::ResourcePtr resptr = Ogre::MaterialManager::getSingleton().getByName(MaterialName);
     Ogre::Material * mat = dynamic_cast<Ogre::Material*>(resptr.getPointer());

     Ogre::Technique *tech = mat->getTechnique(0);    // Get the technique
     Ogre::Pass *pass = tech->getPass(0);            // Get the pass
     _tex_unit = pass->getTextureUnitState(0);        // Get the texture_unit state

     // Get the _overlay
     _overlay = Ogre::OverlayManager::getSingleton().getByName(OverlayName);
     _overlay->hide();

 }
//-----------------------------------------------------------------------------
///
void StaticBillboardSet::updateAll(const Vector3 &cameraDirection)
{
   // s_nSelfInstances will only be greater than 0 if one or more StaticBillboardSet's are using BB_METHOD_ACCELERATED
   if (s_nSelfInstances == 0)
      return;

   //Set shader parameter so material will face camera
   Vector3 forward = cameraDirection;
   Vector3 vRight = forward.crossProduct(Vector3::UNIT_Y);
   Vector3 vUp = forward.crossProduct(vRight);
   vRight.normalise();
   vUp.normalise();

   //Even if camera is upside down, the billboards should remain upright
   if (vUp.y < 0)
      vUp *= -1;

   // Precompute preRotatedQuad for both cases (BBO_CENTER, BBO_BOTTOM_CENTER)
   
   Vector3 vPoint0 = (-vRight + vUp);
   Vector3 vPoint1 = ( vRight + vUp);
   Vector3 vPoint2 = (-vRight - vUp);
   Vector3 vPoint3 = ( vRight - vUp);

   float preRotatedQuad_BBO_CENTER[16] = // single prerotated quad oriented towards the camera
   {
      (float)vPoint0.x, (float)vPoint0.y, (float)vPoint0.z, 0.0f,
      (float)vPoint1.x, (float)vPoint1.y, (float)vPoint1.z, 0.0f,
      (float)vPoint2.x, (float)vPoint2.y, (float)vPoint2.z, 0.0f,
      (float)vPoint3.x, (float)vPoint3.y, (float)vPoint3.z, 0.0f
   };

   vPoint0 = (-vRight + vUp + vUp);
   vPoint1 = ( vRight + vUp + vUp);
   vPoint2 = (-vRight);
   vPoint3 = ( vRight);
   float preRotatedQuad_BBO_BOTTOM_CENTER[16] =
   {
      (float)vPoint0.x, (float)vPoint0.y, (float)vPoint0.z, 0.0f,
      (float)vPoint1.x, (float)vPoint1.y, (float)vPoint1.z, 0.0f,
      (float)vPoint2.x, (float)vPoint2.y, (float)vPoint2.z, 0.0f,
      (float)vPoint3.x, (float)vPoint3.y, (float)vPoint3.z, 0.0f
   };

   // Shaders uniform variables
   static const Ogre::String uScroll = "uScroll", vScroll = "vScroll", preRotatedQuad0 = "preRotatedQuad[0]",
      preRotatedQuad1 = "preRotatedQuad[1]", preRotatedQuad2 = "preRotatedQuad[2]", preRotatedQuad3 = "preRotatedQuad[3]";

   // SVA for Ogre::Material hack
   const GpuConstantDefinition *pGPU_ConstDef_preRotatedQuad0 = 0,
      *pGPU_ConstDef_uScroll = 0, *pGPU_ConstDef_vScroll = 0;

   // For each material in use by the billboard system..
   SBMaterialRefList::iterator i1 = SBMaterialRef::getList().begin(), iend = SBMaterialRef::getList().end();
   while (i1 != iend)
   {
      Ogre::Material *mat = i1->second->getMaterial();

      // Ensure material is set up with the vertex shader
      Pass *p = mat->getTechnique(0)->getPass(0);
      if (!p->hasVertexProgram())
      {
         static const Ogre::String Sprite_vp = "Sprite_vp";
         p->setVertexProgram(Sprite_vp);

         // glsl can use the built in gl_ModelViewProjectionMatrix
         if (!s_isGLSL)
            p->getVertexProgramParameters()->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);

         GpuProgramParametersSharedPtr params = p->getVertexProgramParameters();
         params->setNamedAutoConstant(uScroll, GpuProgramParameters::ACT_CUSTOM);
         params->setNamedAutoConstant(vScroll, GpuProgramParameters::ACT_CUSTOM);
         params->setNamedAutoConstant(preRotatedQuad0, GpuProgramParameters::ACT_CUSTOM);
         params->setNamedAutoConstant(preRotatedQuad1, GpuProgramParameters::ACT_CUSTOM);
         params->setNamedAutoConstant(preRotatedQuad2, GpuProgramParameters::ACT_CUSTOM);
         params->setNamedAutoConstant(preRotatedQuad3, GpuProgramParameters::ACT_CUSTOM);
      }

      // Which prerotated quad use
      const float *pQuad = i1->second->getOrigin() == BBO_CENTER ? preRotatedQuad_BBO_CENTER : preRotatedQuad_BBO_BOTTOM_CENTER;

      // Update the vertex shader parameters
      GpuProgramParametersSharedPtr params = p->getVertexProgramParameters();
      //params->setNamedConstant(preRotatedQuad0, pQuad, 4);
      //params->setNamedConstant(uScroll, p->getTextureUnitState(0)->getTextureUScroll());
      //params->setNamedConstant(vScroll, p->getTextureUnitState(0)->getTextureVScroll());

      // SVA some hack of Ogre::Material.
      // Since material are cloned and use same vertex shader "Sprite_vp" hardware GPU indices
      // must be same. I don`t know planes of Ogre Team to change this behaviour.
      // Therefore this may be unsafe code. Instead of 3 std::map lookups(map::find(const Ogre::String&)) do only 1
      {
         const GpuConstantDefinition *def = params->_findNamedConstantDefinition(preRotatedQuad0, true);
         if (def != pGPU_ConstDef_preRotatedQuad0) // new material, reread
         {
            pGPU_ConstDef_preRotatedQuad0 = def;
            pGPU_ConstDef_uScroll         = params->_findNamedConstantDefinition(uScroll, true);
            pGPU_ConstDef_vScroll         = params->_findNamedConstantDefinition(vScroll, true);
         }
      }

      float fUScroll = (float)p->getTextureUnitState(0)->getTextureUScroll(),
         fVScroll = (float)p->getTextureUnitState(0)->getTextureVScroll();
      params->_writeRawConstants(pGPU_ConstDef_preRotatedQuad0->physicalIndex, pQuad, 16);
      params->_writeRawConstants(pGPU_ConstDef_uScroll->physicalIndex, &fUScroll, 1);
      params->_writeRawConstants(pGPU_ConstDef_vScroll->physicalIndex, &fVScroll, 1);
      
      ++i1; // next material in billboard system
   }
}
Пример #10
0
void saveAsDotScene(const QString& path, QFile& file, Ogre::SceneManager* sceneManager)
{
    Ogre::MeshSerializer* mMeshSerializer = new Ogre::MeshSerializer();
    Ogre::MaterialSerializer* mMaterialSerializer = new Ogre::MaterialSerializer();

    int idCounter = 3;
    if (!file.open(QIODevice::WriteOnly))
    {
        /* show wrror message if not able to open file */
        QMessageBox::warning(0, "Read only", "The file is in read only mode");
    }
    else
    {
        Ogre::SceneManager::MovableObjectIterator iterator = sceneManager->getMovableObjectIterator("Entity");
        QXmlStreamWriter* xmlWriter = new QXmlStreamWriter();
        xmlWriter->setAutoFormatting(true);
        xmlWriter->setDevice(&file);
        xmlWriter->writeStartElement("scene");
        xmlWriter->writeAttribute("formatVersion","");

        xmlWriter->writeStartElement("nodes");
        while(iterator.hasMoreElements())
        {
            Ogre::Entity* e = static_cast<Ogre::Entity*>(iterator.getNext());
            Ogre::Any any = e->getParentNode()->getUserAny();
            Ogre::String widgetType("");
            if(!any.isEmpty()){
                widgetType = any_cast<Ogre::String>(any);
            }
            Ogre::String tmp(widgetType + ":" + e->getParentNode()->getName());
            QString nodeName(tmp.c_str());
            xmlWriter->writeStartElement("node");
            xmlWriter->writeAttribute("name", nodeName);
            xmlWriter->writeAttribute("id", QString::number(idCounter++));


            xmlWriter->writeStartElement("position");
            xmlWriter->writeAttribute("x", QString::number(e->getParentNode()->getPosition().x));
            xmlWriter->writeAttribute("y", QString::number(e->getParentNode()->getPosition().y));
            xmlWriter->writeAttribute("z", QString::number(e->getParentNode()->getPosition().z));
            xmlWriter->writeEndElement();

            xmlWriter->writeStartElement("scale");
            xmlWriter->writeAttribute("x", QString::number(e->getParentNode()->getScale().x));
            xmlWriter->writeAttribute("y", QString::number(e->getParentNode()->getScale().y));
            xmlWriter->writeAttribute("z", QString::number(e->getParentNode()->getScale().z));
            xmlWriter->writeEndElement();

            xmlWriter->writeStartElement("entity");
            xmlWriter->writeAttribute("name", nodeName);
            xmlWriter->writeAttribute("meshFile", nodeName.toLower() + QString(".mesh") );
            xmlWriter->writeAttribute("static", QString("false"));
            xmlWriter->writeEndElement();

            const Mesh* mesh = e->getMesh().getPointer();


            mMeshSerializer->exportMesh(mesh,String(path.toStdString() +
                                                    nodeName.toLower().toStdString() +
                                                    ".mesh" ));


            std::cout << "numeber" <<  mesh->getNumSubMeshes() << std::endl;


            for(int i = 0; i < e->getNumSubEntities(); i++){


                Ogre::Material *mat = static_cast<Ogre::Material*>
                        (Ogre::MaterialManager::getSingletonPtr()->getByName(e->getSubEntity(i)->getMaterialName()).getPointer());

                //e->getMesh().get()->getSubMesh()
                if(mat->getTechnique(0)->getPass(0)->getNumTextureUnitStates() !=0){
                Ogre::String str = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();

            Ogre::MaterialPtr mMatPtr =e->getSubEntity(i)->getMaterial()    ;

            mMaterialSerializer->exportMaterial(mMatPtr ,
                                                String(path.toStdString() +
                                                       nodeName.toLower().toStdString() +
                                                       QString::number(i).toStdString() + ".material" ));
            Ogre::TexturePtr* mTexPtr = new Ogre::TexturePtr(Ogre::TextureManager::getSingletonPtr()->getByName(str));
            Ogre::Texture* mTex = mTexPtr->getPointer();
            Ogre::PixelFormat pxf = mTex->getFormat();
            Ogre::Image mImage;
            mTex->convertToImage(mImage);
            std::cout << str << std::endl;
            mImage.save(String(path.toStdString() +
                                 str));
                }
}
            //material file merge

            for(int i = 0; i < e->getNumSubEntities(); i++){
                Ogre::Material *mat = static_cast<Ogre::Material*>
                        (Ogre::MaterialManager::getSingletonPtr()->getByName(e->getSubEntity(i)->getMaterialName()).getPointer());


                QString mMatFilePath = QString((path.toStdString() +
                                               nodeName.toLower().toStdString() +
                                                ".material").c_str()) ;


                 QFile mFile(mMatFilePath);
                 if (!mFile.open(QIODevice::Append))
                 {
                     /* show wrror message if not able to open file */
                     QMessageBox::warning(0, "Read only", "The file is in read only mode");
                 }
                 else{
                     QTextStream out(&mFile);

                     QString mTempMatPath = QString((path + nodeName.toLower() + QString::number(i) + ".material"));

                     QFile mTempMatFile(mTempMatPath);
                     mTempMatFile.open(QIODevice::ReadOnly);

                     QTextStream src(&mTempMatFile);

                     mFile.write(src.readAll().toStdString().c_str());
                     mTempMatFile.remove();

                 }



            }


            xmlWriter->writeEndElement();


        }

        xmlWriter->writeEndElement();
        xmlWriter->writeEndDocument();
        delete xmlWriter;
    }

    delete mMeshSerializer;
    delete mMaterialSerializer;
}
Пример #11
0
void GameState::createScene()
{
	// CREATE 3D SCENE
	
    m_bQuit					= false;
	
	_highScoreEntryDialog	= nullptr;
	_gameTime				= 0.0f;
	_physicsTime			= 0.0f;
	_playerScore			= 0.0f;
	_pauseState				= PAUSE_STATE_NONE;
	_pulsePower				= 0.0f;
	_pulseTime				= 0.0f;
	_gameOverTime			= 0.0f;

	_energyDrainFactor		= 1.0f;
	_vibrationStrength		= 0.0f;

	// BULLET SETUP
	
	 // Build the broadphase
    _btBroadphase = new (alignedMalloc<btDbvtBroadphase>()) btDbvtBroadphase();
 
    // Set up the collision configuration and dispatcher
    _btCollisionConfiguration = new (alignedMalloc<btDefaultCollisionConfiguration>()) btDefaultCollisionConfiguration();
    _btDispatcher = new (alignedMalloc<btCollisionDispatcher>()) btCollisionDispatcher(_btCollisionConfiguration);
 
    // The actual physics solver
    _btSolver = new (alignedMalloc<btSequentialImpulseConstraintSolver>()) btSequentialImpulseConstraintSolver;
 
    // The world.
    _btDynamicsWorld = new (alignedMalloc<btDiscreteDynamicsWorld>()) btDiscreteDynamicsWorld(_btDispatcher,_btBroadphase,_btSolver,_btCollisionConfiguration);
    _btDynamicsWorld->setGravity(btVector3(0,-10,0));

	_btGroundShape = new (alignedMalloc<btStaticPlaneShape>()) btStaticPlaneShape(btVector3(0,1,0),1);
	_btGroundMotionState = new (alignedMalloc<btDefaultMotionState>()) btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
	btRigidBody::btRigidBodyConstructionInfo  groundRigidBodyCI(0,_btGroundMotionState,_btGroundShape,btVector3(0,0,0));
    _btGroundRigidBody = new (alignedMalloc<btRigidBody>()) btRigidBody(groundRigidBodyCI);
	assert((int)_btGroundRigidBody % 16 == 0);
	_btGroundRigidBody->setRestitution(1.0f);
	_btGroundRigidBody->setActivationState(DISABLE_DEACTIVATION);

	_btDynamicsWorld->addRigidBody(_btGroundRigidBody,COL_STATIC,COL_ALL);

	// CREATE ACTORS

	_playerBase = new LagomPlayerBase(this);

	boost::shared_ptr<LagomPlayerBase> playerBase(_playerBase);

	RegisterActor(playerBase);

	// Effects stuff

	_particleManager = new LagomParticleManager(m_pSceneMgr,_btDynamicsWorld,1000,0.5f);
	_billboardManager = new BillboardManager(m_pSceneMgr,m_pCamera);
	
	//need a HUD too!
	
	Gorilla::Silverback*		silverback = Gorilla::Silverback::getSingletonPtr(); 

	_gScreen[0] = silverback->createScreen(Lagom::getSingleton().m_pViewport, "LargeFont");
	_gScreen[1] = silverback->createScreen(Lagom::getSingleton().m_pViewport, "MediumFont");
	_gScreen[2] = silverback->createScreen(Lagom::getSingleton().m_pViewport, "SmallFont");
	_gTutorialScreen = silverback->createScreen(Lagom::getSingleton().m_pViewport, "dejavu");
	_gLayer[0] = _gScreen[0]->createLayer(12);
	_gLayer[1] = _gScreen[1]->createLayer(13);
	_gLayer[2] = _gScreen[2]->createLayer(15);
	_gTutorialLayer = _gTutorialScreen->createLayer(18);

	int x,y,w,h;
	Lagom::getSingleton().m_pViewport->getActualDimensions(x,y,w,h);
	
	_gDisplays[0]._gText = _gLayer[1]->createCaption(24,w/2,h, "");
	_gDisplays[1]._gText = _gLayer[0]->createCaption(48,w/2,h, "");
	_gDisplays[2]._gText = _gLayer[1]->createCaption(24,w/2,h, "");

	for(auto it = _gDisplays.begin(); it< _gDisplays.end(); ++it)
	{
		it->_text = "";
		it->_displayPingTime = 0.0f;
		it->_displayVisibleTime = 0.0f;
		it->_gText->align(Gorilla::TextAlign_Centre);
	}

	_gDisplays[0]._gText->vertical_align(Gorilla::VerticalAlign_Top);
	_gDisplays[0]._gText->top(0+5);
	_gDisplays[1]._gText->vertical_align(Gorilla::VerticalAlign_Middle);
	_gDisplays[1]._gText->top(h/2);
	_gDisplays[2]._gText->vertical_align(Gorilla::VerticalAlign_Bottom);
	_gDisplays[2]._gText->top(h-5);
	_gameTime= 0.0f;
	_displayTime = 0.0f;
	_inputTime = 0.0;

	//set up fader
	Ogre::ResourcePtr resptr = Ogre::MaterialManager::getSingleton().getByName("fadeToBlackMaterial");
    Ogre::Material * mat = dynamic_cast<Ogre::Material*>(resptr.getPointer());
 
    Ogre::Technique *tech = mat->getTechnique(0);    // Get the technique
    Ogre::Pass *pass = tech->getPass(0);            // Get the pass
    _fadeTexUnit = pass->getTextureUnitState(0);        // Get the texture_unit state
 
    _fadeOverlay = Ogre::OverlayManager::getSingleton().getByName("fadeToBlackOverlay");

	//set overlay to black
    _fadeOverlay->show();
    _fadeTexUnit->setAlphaOperation(LBX_MODULATE, LBS_MANUAL, LBS_TEXTURE, 1.0f);
	
	calculatePlayArea();
	//now load level if any

	_stageSpawner = new StageSpawnManager(this,playerBase);

	// set proper state for fade in

	SetPauseState(PAUSE_STATE_FADING);
	_fadeFactor = -1.0f;
}