void SalamancerApplication::createBrowser(){
    Ogre::TexturePtr renderTexture = Ogre::TextureManager::getSingleton().createManual(
                "texture",
                Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                Ogre::TEX_TYPE_2D, mWindow->getWidth(), mWindow->getHeight(), 0, Ogre::PF_A8R8G8B8, Ogre::TU_WRITE_ONLY);

    Ogre::MaterialPtr material = Ogre::MaterialManager::getSingletonPtr()->create("BrowserMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    material->getTechnique(0)->getPass(0)->setCullingMode(Ogre::CULL_CLOCKWISE); // print both sides of the polygones
    material->getTechnique(0)->getPass(0)->createTextureUnitState("texture");
    material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
    material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    
    Ogre::Overlay *overlay = Ogre::OverlayManager::getSingletonPtr()->create("BrowserOverlay");
    Ogre::OverlayContainer* panel = static_cast<OverlayContainer*>(Ogre::OverlayManager::getSingletonPtr()->createOverlayElement("Panel", "BrowserPanel"));
    
    panel->setPosition(0.0, 0.0);
    panel->setDimensions(1.0, 1.0);
    panel->setMaterialName("BrowserMaterial");
    overlay->add2D(panel);
    
    overlay->show();
    
    this->windowInfo.SetAsWindowless(0, true);
    
    this->clientHandler = new ClientHandler(renderTexture, this->mRoot->getAutoCreatedWindow(), mMouse, this->mCamera, this->mSceneMgr, this->world, this->context);
    
    browserSettings.web_security = STATE_DISABLED;
    
    this->browser = CefBrowserHost::CreateBrowserSync(windowInfo, this->clientHandler.get(),
            "file:///home/nathan/Projects/salamancer/dist/bin/hud/index.html",
            browserSettings, 
            NULL);
    
    this->clientHandler->SetBrowser(this->browser);
    
    mRoot->addFrameListener(this->clientHandler.get());
    
}
Ogre::MaterialPtr AssetLoader::createMaterial(Ogre::String name, int index, aiMaterial* mat)
{
	Ogre::MaterialManager* omatMgr = Ogre::MaterialManager::getSingletonPtr();

	std::ostringstream matname;
	matname << name.data() << "_mat";
	matname.widen(4);
	matname.fill('0');
	matname << index;
	Ogre::String matName = matname.str();

	Ogre::ResourceManager::ResourceCreateOrRetrieveResult status = omatMgr->createOrRetrieve(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
	Ogre::MaterialPtr omat = status.first;

	aiColor4D clr(1.0, 1.0, 1.0, 1.0);
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_DIFFUSE, &clr);
	omat->getTechnique(0)->getPass(0)->setDiffuse(clr.r, clr.g, clr.b, clr.a);
	
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_SPECULAR, &clr);
	omat->getTechnique(0)->getPass(0)->setSpecular(clr.r, clr.g, clr.b, clr.a);
	
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_AMBIENT, &clr);
	omat->getTechnique(0)->getPass(0)->setAmbient(clr.r, clr.g, clr.b);
	
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_EMISSIVE, &clr);
	omat->getTechnique(0)->getPass(0)->setSelfIllumination(clr.r, clr.g, clr.b);

	omat->getTechnique(0)->getPass(0)->setShadingMode(Ogre::SO_GOURAUD);
	omat->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
	omat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
	omat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(true);
	//omat->getTechnique(0)->getPass(0)->setVertexColourTracking(Ogre::TVC_DIFFUSE);
	
	aiString path;
	aiReturn res = mat->GetTexture(aiTextureType_DIFFUSE, 0, &path);
	if (res == AI_SUCCESS) {
		Ogre::TextureUnitState* stateBase = omat->getTechnique(0)->getPass(0)->createTextureUnitState();
		stateBase->setColourOperation(Ogre::LBO_MODULATE);
		stateBase->setTextureName(path.data);
	}
	
	return omat;
}
Example #3
0
void GodRaysListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	if(pass_id !=1 
		&& pass_id !=2
		&& pass_id !=3
		)
	{
		return ;
	}
	 // this is the camera you're using
    #ifndef ROAD_EDITOR
	Ogre::Camera *cam = mApp->mSplitMgr->mCameras.front();
	#else
	Ogre::Camera *cam = mApp->mCamera;
	#endif

	//update the sun position
	Ogre::Light* sun =((App*)mApp)->sun;
	Ogre::GpuProgramParametersSharedPtr params= mat->getTechnique(0)->getPass(0)->getVertexProgramParameters();
	Ogre::GpuProgramParametersSharedPtr fparams= mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
	//disable god rays when the sun is not facing us
	float enable=0.0f;
	if(sun != NULL)
	{
		Ogre::Vector3 sunPosition = sun->getDirection() *100;
		Ogre::Vector3 worldViewPosition = cam->getViewMatrix() * sunPosition;
		Ogre::Vector3 hcsPosition = cam->getProjectionMatrix() * worldViewPosition;
		float unclampedLuminance = abs(hcsPosition.x)+abs(hcsPosition.y);
		clamp(hcsPosition);		
		Ogre::Vector2 sunScreenSpacePosition = Ogre::Vector2(0.5f + (0.5f * hcsPosition.x), 0.5f + (0.5f * -hcsPosition.y));
		SunScreenSpacePosition = Ogre::Vector4 ( sunScreenSpacePosition.x, sunScreenSpacePosition.y, 0, 1 );
		enable = (1.0f / ((unclampedLuminance > 1.0f) ? unclampedLuminance : 1.0f)) * (hcsPosition.z < 1 ? 0.0f : 1.0f);
	}
	
	params->setNamedConstant("lightPosition", SunScreenSpacePosition);
	fparams->setNamedConstant("enableEffect", enable);
	
}
//----------------------------------------------------------------------------------------
 void PortalOutlineRenderable::createPortalMaterials(void)
 {
	Ogre::ColourValue colour = Ogre::ColourValue(0,1,0);//
	Ogre::String matname = "PortalOutlineMaterial";

	Ogre::ResourceManager::ResourceCreateOrRetrieveResult result = Ogre::MaterialManager::getSingleton().createOrRetrieve(matname, "General");
	if(result.second)
	{
		Ogre::MaterialPtr freePortalMaterial = result.first;
	    freePortalMaterial->setReceiveShadows(false);
	    freePortalMaterial->getTechnique(0)->setLightingEnabled(true);
	    freePortalMaterial->getTechnique(0)->getPass(0)->setDiffuse(colour);
	    freePortalMaterial->getTechnique(0)->getPass(0)->setAmbient(colour);
	    freePortalMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(colour);
	}

	colour = Ogre::ColourValue(1,1,0);//Yellow
	matname = "PortalOutlineMaterialConnected";
	result = Ogre::MaterialManager::getSingleton().createOrRetrieve(matname, "General");
	if(result.second)
	{
		Ogre::MaterialPtr connectedPortalMaterial = result.first;
	    connectedPortalMaterial->setReceiveShadows(false);
	    connectedPortalMaterial->getTechnique(0)->setLightingEnabled(true);
	    connectedPortalMaterial->getTechnique(0)->getPass(0)->setDiffuse(colour);
	    connectedPortalMaterial->getTechnique(0)->getPass(0)->setAmbient(colour);
	    connectedPortalMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(colour);
	}

	colour = Ogre::ColourValue(1,0,0);//Red
	matname = "PortalOutlineMaterialLinked";
	result = Ogre::MaterialManager::getSingleton().createOrRetrieve(matname, "General");
	if(result.second)
	{
		Ogre::MaterialPtr linkedPortalMaterial = result.first;
	    linkedPortalMaterial->setReceiveShadows(false);
	    linkedPortalMaterial->getTechnique(0)->setLightingEnabled(true);
	    linkedPortalMaterial->getTechnique(0)->getPass(0)->setDiffuse(colour);
	    linkedPortalMaterial->getTechnique(0)->getPass(0)->setAmbient(colour);
	    linkedPortalMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(colour);
	}

 }
//-------------------------------------------------------------------------------
Ogre::MaterialPtr CSceneManagerEditor::buildDepthShadowMaterial(Ogre::MaterialPtr cpyMat)
{
    if(mShadowsTechnique->get() >= (int)Ogre::SHADOWTYPE_TEXTURE_ADDITIVE && mShadowsTechnique->get() <= (int)Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED)
    {
        Ogre::String matName = "DepthShadows/" + cpyMat->getName();

        Ogre::MaterialPtr ret = Ogre::MaterialManager::getSingleton().getByName(matName);
        if (ret.isNull())
        {
            ret = cpyMat->clone(matName);

            Ogre::Technique *t = ret->getTechnique(0);
            t->setShadowCasterMaterial("Ogre/shadow/depth/caster");
            Ogre::Pass *p = t->getPass(0);
            p->setVertexProgram("Ogre/shadow/receiver/depth/pssm3/vp");
            p->setFragmentProgram("Ogre/shadow/receiver/depth/pssm3/fp");

            Ogre::TextureUnitState *tu = p->createTextureUnitState();
            tu->setName("shadow0");
            tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW);
            tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER);
            tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1));
            
            tu = p->createTextureUnitState();
            tu->setName("shadow1");
            tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW);
            tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER);
            tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1));
            
            tu = p->createTextureUnitState();
            tu->setName("shadow2");
            tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW);
            tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER);
            tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1));

            Ogre::Vector4 splitPoints;
            const Ogre::PSSMShadowCameraSetup::SplitPointList& splitPointList = 
                static_cast<Ogre::PSSMShadowCameraSetup*>(mPSSMSetup.get())->getSplitPoints();
            for (int i = 0; i < 3; ++i)
            {
                splitPoints[i] = splitPointList[i];
            }
            p->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints);
        }
        
        return ret;
    }
    else
        return cpyMat;
}
Example #6
0
static void
SubEntity_tintColour(
    SubEntity* self,
    const String& groupName,
    const String& materialName,
    const Ogre::ColourValue& colour
) {
    Ogre::MaterialPtr baseMaterial = Ogre::MaterialManager::getSingleton().getByName(materialName);
    Ogre::MaterialPtr materialPtr = baseMaterial->clone(groupName);
    materialPtr->compile();
    Ogre::TextureUnitState* ptus = materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0);
    ptus->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_TEXTURE, colour);
    self->setMaterial(materialPtr);
}
Example #7
0
    CreateObjectAction::CreateObjectAction(SceneManipulator* sceneManipulator)
        : Action(sceneManipulator)
        , mDirty(true)
        , mObject()
		, mHasPosition(false)
		, mRangeSphereEntity(NULL)
		, mRangeSphereNode(NULL)
    {
		// create a entity for indicate the range of a point light
		mRangeSphereNode = getIndicatorRootSceneNode()->createChildSceneNode();

		Ogre::MeshPtr sphereMesh = Fairy::createCommonSphere("PointLightRangeSphere", 100, 16, 16);
		Ogre::MaterialPtr material = Fairy::createPureColourMaterial(Ogre::ColourValue(0, 1, 0, 0.75));

		material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME);
		material->getTechnique(0)->getPass(0)->setCullingMode(Ogre::CULL_NONE);

		mRangeSphereEntity = getSceneManager()->createEntity("CreateLightRangeSphere", sphereMesh->getName());
		mRangeSphereEntity->setMaterialName(material->getName());

		mRangeSphereNode->attachObject(mRangeSphereEntity);
		mRangeSphereNode->setVisible(false);
    }
void SplashScreenState::createScene()
{
	// creation image splash screen
	Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("SplashScreen", "General");
	material->getTechnique(0)->getPass(0)->createTextureUnitState("splash_screen.jpg");
	material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
	material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
	material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
	// creation rect
	Ogre::Rectangle2D *rect = new Ogre::Rectangle2D(true);
	rect->setCorners(-1.0, 1.0, 1.0, -1.0);
	rect->setMaterial("SplashScreen");
	// priorité chargement
	rect->setRenderQueueGroup(Ogre::RenderQueueGroupID::RENDER_QUEUE_BACKGROUND);
	// stay visible
	Ogre::AxisAlignedBox aabInf;
	aabInf.setInfinite();
	rect->setBoundingBox(aabInf);
	//
	Ogre::SceneNode* node = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("SplashScreen");
	node->attachObject(rect);
	m_pSceneMgr->setAmbientLight(Ogre::ColourValue(1, 1, 1));
}
Example #9
0
void EC_SkyBox::SetTextures()
{
    if (!ViewEnabled())
        return;

    AssetReferenceList lst = textureRefs.Get();
    std::vector<std::string> texture_names;
    texture_names.reserve(6);

    for(int i = 0; i < lst.Size() && i <= 6; ++i)
        texture_names.push_back(lst[i].ref.toStdString());

    Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(materialRef.Get().ref.toStdString().c_str());
    if (!materialPtr.isNull() && texture_names.size() == 6)
        materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setCubicTextureName(&texture_names[0], false);
        //skyMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureScale(1, -1);
    else if(!materialPtr.isNull() )
        for(int i = 0; i < texture_names.size(); ++i)
            materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setFrameTextureName(Ogre::String(texture_names[i].c_str()), i);

    DisableSky();
    CreateSky();
}
Example #10
0
//create Color texture
void KinectDevice::createOgreColorTexture(const std::string colorTextureName, const std::string materialName)
{
	if(!colorTextureName.empty())
	{
		mColorTexture = TextureManager::getSingleton().createManual(
			colorTextureName, 
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
			TEX_TYPE_2D, 
			KINECT_DEPTH_WIDTH, 
			KINECT_DEPTH_HEIGHT, 
			0,
			PF_R8G8B8, 
			TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
	}
	if(!materialName.empty())
	{
		//Create Material
		Ogre::MaterialPtr material = MaterialManager::getSingleton().create(materialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
		material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
		material->getTechnique(0)->getPass(0)->createTextureUnitState(colorTextureName);
		material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureRotate(Ogre::Degree(180)); 
	}
}
Example #11
0
//create User texture
void KinectDevice::createOgreUserTexture(const std::string UserTextureName, const std::string materialName)
{
	if(!UserTextureName.empty())
	{		
		mUserTexture  = TextureManager::getSingleton().createManual(
			UserTextureName, // name
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_2D,      // type
			KINECT_DEPTH_WIDTH, KINECT_DEPTH_HEIGHT,// width & height
			0,                // number of mipmaps
			PF_BYTE_BGRA,     // pixel format
			TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
	}
	if(!materialName.empty())
	{
		// Create a material using the texture
		Ogre::MaterialPtr material = MaterialManager::getSingleton().create(
				materialName, // name
				ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		material->getTechnique(0)->getPass(0)->createTextureUnitState(UserTextureName);
		material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureRotate(Ogre::Degree(180)); 
		//material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
	}
}
Example #12
0
void CubeWorld::createWaterTexture (const TCHAR* pName)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();

	tech->setLightingEnabled(false);

	pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
	pass->setDepthWriteEnabled(false);

	tex->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(0, 0, 1));
	tex->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.5);
}
Example #13
0
CEGUIVideoPlayer::CEGUIVideoPlayer(
    std::string name,
    int width,
    int height
) : CEGUIWindow("Thrive/Image",name)
{
    Ogre::MaterialPtr videoMaterial = Ogre::MaterialManager::getSingleton().create(
                "VideoMaterial"+name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    m_videoMaterialPass = videoMaterial->getTechnique( 0 )->getPass( 0 );
    m_videoPlayer = std::unique_ptr<Video::VideoPlayer>(new Video::VideoPlayer());
    //m_videoPlayer->setAudioFactory(new FFMPEGAudioFactory()); Don't know what I need to do to make audio work
    m_videoImage = static_cast<CEGUI::BitmapImage*>(&CEGUI::ImageManager::getSingleton().create("BitmapImage", "ThriveGeneric/VideoImage"));
    m_window->setWidth(CEGUI::UDim(0,width));
    m_window->setHeight(CEGUI::UDim(0,height));
}
void MainApplication::shoot()
{
    
    Ogre::String number2 = Ogre::StringConverter::toString(shotCounter + 1); 
    shots.push_back("manual1_node" + number2);
    /*
    Ogre::Entity* ogreHead = mSceneMgr -> createEntity("ogrehead.mesh");
    Ogre::SceneNode *headNode = mSceneMgr -> getRootSceneNode() -> createChildSceneNode("manual1_node" + number2);
    Ogre::Vector3 pos1(mSceneMgr-> getSceneNode("NinjaNode")->getPosition());
    headNode -> setPosition(pos1);
    headNode -> attachObject(ogreHead);
    */
    Ogre::ManualObject* myManualObject =  mSceneMgr->createManualObject("manual1" + number2); 
    Ogre::SceneNode* myManualObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("manual1_node" + number2); 
     
    // NOTE: The second parameter to the create method is the resource group the material will be added to.
    // If the group you name does not exist (in your resources.cfg file) the library will assert() and your program will crash
    Ogre::MaterialPtr myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("manual1Material","General"); 
    myManualObjectMaterial->setReceiveShadows(false); 
    myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
    myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,0,1,0); 
    myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(0,0,1); 
    myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,1); 
    //myManualObjectMaterial->dispose();  // dispose pointer, not the material
     
    Ogre::Vector3 pos1(mSceneMgr-> getSceneNode("NinjaNode")->getPosition());//Get position of player
     
    myManualObject->begin("manual1Material", Ogre::RenderOperation::OT_LINE_LIST); 
    myManualObject->position(pos1.x + 20, pos1.y, pos1.z); 
    myManualObject->position(pos1.x + 50, pos1.y, pos1.z); 
    // etc 
    myManualObject->end(); 
    myManualObjectNode->attachObject(myManualObject);
    shotCounter++;
    
}
void IntroState::createScene()
{
	MaterialPtr material = MaterialManager::getSingleton().create("Background", "General");
	material->getTechnique(0)->getPass(0)->createTextureUnitState("rockwall.tga");
	material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
	material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
	material->getTechnique(0)->getPass(0)->setLightingEnabled(false);

 
//Ustvarimo 2D kvadrat, ki prekrije celonti ekrat
	Rectangle2D* rect = new Rectangle2D(true);
	rect->setCorners(-1.0, 1.0, 1.0, -1.0);
	rect->setMaterial("Background");
 
	//najprej renderiramo ozadje potem pa vse ostalo
	rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);
 
	rect->setBoundingBox(AxisAlignedBox(-100000.0*Ogre::Vector3::UNIT_SCALE, 100000.0*Ogre::Vector3::UNIT_SCALE));
 
	// pripnemo teksturo na ozadje
	SceneNode* node = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("Background");
	node->attachObject(rect);

	Ogre::MaterialPtr mat;
	Ogre::TextureUnitState* tex;
 
	Ogre::String materialName="Background";
	if (!Ogre::MaterialManager::getSingleton().resourceExists(materialName))
	{
		throw("Error, material doesn't exist!");
	}

	//tukaj prilepimo film na prej ustvarjeno teksturo
	mat=Ogre::MaterialManager::getSingleton().getByName(materialName);
	tex=mat->getTechnique(0)->getPass(0)->getTextureUnitState(0);
	tex->setTextureName(dshowMovieTextureSystem->getMovieTexture()->getName());

	mTitleLabel->setCaption("Intro");
	mTitleLabel->show();

	mTitleLabel2->setCaption("Press ESC to Exit Game!");
	mTitleLabel2->show();

	mTitleLabel3->setCaption("Press Space to skip!");
	mTitleLabel3->show();


}
 void StereoController::ChangeShaderColour(qreal r, qreal g, qreal b,const Ogre::String& name)
 {
     try
     {
         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName("Stereo/Anaglyph");
         Ogre::Pass* pass = mat->getTechnique(0)->getPass(0);
         Ogre::GpuProgramParametersSharedPtr param = pass->getFragmentProgramParameters();
         Ogre::ColourValue colour(r,g,b,1);
         param->setNamedConstant(name, colour);
     }
     catch (Ogre::Exception &e)
     {
         LogWarning("StereoController: Failed to set Anaglyph shader constant.");
         LogWarning(e.what());
     }
 }
Example #17
0
void DemoApp::startDemo()
{
	new OgreFramework();
	if(!OgreFramework::getSingletonPtr()->initOgre("DemoApp v1.0", this, 0))
		return;
    
	m_bShutdown = false;
    
	OgreFramework::getSingletonPtr()->m_pLog->logMessage("Demo initialized!");
	
#ifdef USE_RTSHADER_SYSTEM
    initializeRTShaderSystem(OgreFramework::getSingletonPtr()->m_pSceneMgr);
    Ogre::MaterialPtr baseWhite = Ogre::MaterialManager::getSingleton().getByName("BaseWhite", Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);				
    baseWhite->setLightingEnabled(false);
    mShaderGenerator->createShaderBasedTechnique(
                                                 "BaseWhite", 
                                                 Ogre::MaterialManager::DEFAULT_SCHEME_NAME, 
                                                 Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);	
    mShaderGenerator->validateMaterial(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, 
                                       "BaseWhite");
    baseWhite->getTechnique(0)->getPass(0)->setVertexProgram(
                                                             baseWhite->getTechnique(1)->getPass(0)->getVertexProgram()->getName());
    baseWhite->getTechnique(0)->getPass(0)->setFragmentProgram(
                                                               baseWhite->getTechnique(1)->getPass(0)->getFragmentProgram()->getName());
    
    // creates shaders for base material BaseWhiteNoLighting using the RTSS
    mShaderGenerator->createShaderBasedTechnique(
                                                 "BaseWhiteNoLighting", 
                                                 Ogre::MaterialManager::DEFAULT_SCHEME_NAME, 
                                                 Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);	
    mShaderGenerator->validateMaterial(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, 
                                       "BaseWhiteNoLighting");
    Ogre::MaterialPtr baseWhiteNoLighting = Ogre::MaterialManager::getSingleton().getByName("BaseWhiteNoLighting", Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
    baseWhiteNoLighting->getTechnique(0)->getPass(0)->setVertexProgram(
                                                                       baseWhiteNoLighting->getTechnique(1)->getPass(0)->getVertexProgram()->getName());
    baseWhiteNoLighting->getTechnique(0)->getPass(0)->setFragmentProgram(
                                                                         baseWhiteNoLighting->getTechnique(1)->getPass(0)->getFragmentProgram()->getName());
#endif
    
	setupDemoScene();
#if !((OGRE_PLATFORM == OGRE_PLATFORM_APPLE) && __LP64__)
	runDemo();
#endif
}
void EC_OgreMovableTextOverlay::SetAlphaChannelIntensity(const float &distance)
{
    float materialAlpha, textAlpha;

    textAlpha = (MAX_VISIBILITY_DISTANCE - distance) / MAX_VISIBILITY_DISTANCE;
    materialAlpha = (MAX_VISIBILITY_DISTANCE - distance) / MAX_VISIBILITY_DISTANCE;
    if (materialAlpha > materialMaxAlpha_)
        materialAlpha = materialMaxAlpha_;

    Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
    Ogre::MaterialPtr material = mm.getByName(materialName_);
    if (material.get())
        material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(
            Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, materialAlpha, materialAlpha, 0);

    text_element_->setColour(Ogre::ColourValue(fontColor_.r, fontColor_.g, fontColor_.b, textAlpha));
}
Example #19
0
int gkHUDElement::getMaterialAlphaRejectValue()
{
	if (!m_element) return 0;

	try
	{
		Ogre::MaterialPtr material = m_element->getMaterial();
		Ogre::Pass* pass = material->getTechnique(0)->getPass(0);
		return pass->getAlphaRejectValue();
	}
	catch (Ogre::Exception& e)
	{
		gkPrintf("HUD Error: %s", e.what());
	}

	return 0;
}
Example #20
0
void CubeWorld::createTexture (const TCHAR* pName, const TCHAR* pImageFilename)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();

	tex->setTextureName(pImageFilename);
	tex->setNumMipmaps(4);
	tex->setTextureAnisotropy(1);
	tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);

	pass->setVertexColourTracking(Ogre::TVC_DIFFUSE);
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_DIFFUSE, Ogre::LBS_TEXTURE);

	tech->setLightingEnabled(false);
}
Example #21
0
WorldModel::WorldModel (Ogre::SceneManager *sm) :
    scenemgr_ (sm)
{
    // Create the camera
    camera_ = scenemgr_->createCamera("PlayerCam");

    // Position it at 500 in Z direction
    camera_->setPosition(Vector3(0,0,500));

    // Look back along -Z
    camera_->lookAt(Vector3(0,0,-300));
    camera_->setNearClipDistance(5);

    // Set ambient light
    scenemgr_->setAmbientLight(ColourValue(0.2f, 0.2f, 0.2f));

    // Create a light
    scenemgr_->createLight("MainLight")->setPosition(20, 80, 50);

    // Position the camera
    camera_->setPosition(60, 200, 70);
    camera_->lookAt(0, 0, 0);

    // Create a material for the plane (just a simple texture, here grass.jpg)
    Ogre::MaterialPtr m = Ogre::MaterialManager::getSingleton().
                          create ("PlaneMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

    Ogre::TextureUnitState* t = m->getTechnique(0)->getPass(0)->
                                createTextureUnitState ("test.jpg");

    // Create a simple plane
    Ogre::MovablePlane *plane = new Ogre::MovablePlane ("Plane");
    plane->d = 0;
    plane->normal = Vector3::UNIT_Y;

    Ogre::MeshManager::getSingleton().
    createPlane ("PlaneMesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                 *plane, 120, 120, 1, 1, true, 1, 1, 1, Vector3::UNIT_Z);

    Ogre::Entity *planeent = scenemgr_-> createEntity ("PlaneEntity", "PlaneMesh");
    planeent-> setMaterialName ("PlaneMat");

    // Attach the plane to a scene node
    planenode_ = scenemgr_-> getRootSceneNode()-> createChildSceneNode ();
    planenode_-> attachObject (planeent);
}
Example #22
0
void gkHUDElement::setMaterialAlphaRejectValue(int val, bool isGreater)
{
	if (!m_element) return;
	int alpha = gkClamp(val, 0, 255);
	try
	{
		Ogre::MaterialPtr material = m_element->getMaterial();
		Ogre::Pass* pass = material->getTechnique(0)->getPass(0);
		if (isGreater)
			pass->setAlphaRejectSettings(Ogre::CMPF_GREATER, alpha);
		else
			pass->setAlphaRejectSettings(Ogre::CMPF_LESS_EQUAL, alpha);
	}
	catch (Ogre::Exception& e)
	{
		gkPrintf("HUD Error: %s", e.what());
	}
}
Example #23
0
void PortalEditor::_createMaterial()
{
    // create a transparent material for the portal plane.
    //The plane only exists to make it selectable, so we don't want to see it
    Ogre::MaterialPtr       material;
    //TODO:  **********************ModularZone Resource Group ??? *******************************
    Ogre::ResourceManager::ResourceCreateOrRetrieveResult result = Ogre::MaterialManager::getSingleton().createOrRetrieve("MZP_Portal_Material", "General");
    if(result.second)
    {
#if (OGRE_VERSION < ((1 << 16) | (9 << 8) | 0))
        material = result.first;
#else
        material = result.first.staticCast<Ogre::Material>();
#endif
        material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_POINTS);
    }

}
HudDial::HudDial(hud_part_design_t& a_hud_part_design)
  : HudPart(a_hud_part_design)
{
  // read params from design
  if (a_hud_part_design.parameters.size() < 4) { // kill the game if too few params
    Game::kill(string("hud_part missing params: ") + a_hud_part_design.name);
  }
  min_value = a_hud_part_design.parameters[0];
  max_value = a_hud_part_design.parameters[1];
  min_angle = a_hud_part_design.parameters[2];
  max_angle = a_hud_part_design.parameters[3];

  // start with min_value
  value = min_value;

  // create texture for the dial
  Ogre::MaterialPtr material = GameHud::createOverlayMaterial(a_hud_part_design.name);
  dial_texture = material->getTechnique(0)->getPass(0)->getTextureUnitState(0);

  // apply it to the main container
  Container->setMaterialName(a_hud_part_design.name);
  // repostition to centre around x, y
  Container->setPosition(position.first - (size.first * 0.5),
                         position.second - (size.second * 0.5));

  // bind the appropriate function for getting the value to the funciton pointer
  if (function == hud_part_enum::speed) {
    getValue = getValueSpeed;
  } else if (function == hud_part_enum::pressure) {
    getValue = getValuePressure;
  } else if (function == hud_part_enum::coolant) {
    getValue = getValueCoolant;
  } else if (function == hud_part_enum::temperature_engine) {
    getValue = getValueEngineTemperature;
  } else if (function == hud_part_enum::temperature) {
    getValue = getValueCoreTemperature;
  } else if (function == hud_part_enum::temperature_external) {
    getValue = getValueExternalTemperature;
  } else if (function == hud_part_enum::throttle) {
    getValue = getValueThrottle;
  } else { // not handled or not handled yet
    getValue = getValueZero;
  }
}
Example #25
0
void EC_Sky::OnTextureAssetLoaded(AssetPtr tex)
{
    std::vector<std::string> texture_names;
    texture_names.reserve(cSkyBoxTextureCount);
    
    AssetReferenceList textureList = textureRefs.Get();

    const char * const defaultSkyTextures[cSkyBoxTextureCount] =
    {   "rex_sky_front.dds",
        "rex_sky_back.dds",
        "rex_sky_left.dds",
        "rex_sky_right.dds",
        "rex_sky_top.dds",
        "rex_sky_bot.dds"
    };

    for(size_t i = 0; i < textureAssets.size() || i < cSkyBoxTextureCount; ++i)
        if (i < textureAssets.size() && textureAssets[i])
        {
            AssetPtr asset = textureAssets[i]->Asset();
            TextureAsset *textureAsset = dynamic_cast<TextureAsset*>(asset.get());
            if (textureAsset)
                texture_names.push_back(textureAsset->ogreAssetName.toStdString());
            else
                texture_names.push_back(defaultSkyTextures[i]);
        }
        else
            texture_names.push_back(defaultSkyTextures[i]);

    assert(texture_names.size() == cSkyBoxTextureCount);

    ///\todo Use AssetAPI for the material.
    Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(materialRef.Get().ref.toStdString().c_str());
    if (materialPtr.isNull())
    {
        LogError("EC_Sky::OnTextureAssetLoaded: Cannot find Ogre material \"" + materialRef.Get().ref.toStdString() + "\"!");
        return;
    }
    if (materialPtr->getNumTechniques() == 0 || materialPtr->getTechnique(0) == 0 ||
        materialPtr->getTechnique(0)->getNumPasses() == 0 || materialPtr->getTechnique(0)->getPass(0) == 0 ||
        materialPtr->getTechnique(0)->getPass(0)->getNumTextureUnitStates() == 0 ||
        materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0) == 0)
    {
        LogError("EC_Sky::OnTextureAssetLoaded: Cannot use material \"" + materialRef.Get().ref.toStdString() + "\" as Skybox material: It has 0 techniques, passes or texture unit states!");
        return;
    }

    materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setCubicTextureName(&texture_names[0], false);
    
    CreateSky();    
}
Example #26
0
        Ogre::Pass *getPass(const string &matName, size_t t, size_t p, bool clone)
        {
            if (!Ogre::MaterialManager::getSingleton().resourceExists(matName))
            {
                log("Could not find \"" + matName + "\" material");
                return NULL;
            }

            Ogre::MaterialPtr mat = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().load(
                matName, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
            assert(mat.get());

            static idGen id;

            if (clone)
                mat = mat->clone(id(matName));

            return mat->getTechnique(t)->getPass(p);
        }
Example #27
0
void BallApp::createBall(std::string entName, std::string nodeName, 
                        int x, int y, int z,
                        int vx, int vy, int vz) {
  
  Ogre::Entity *entity = mSceneMgr->createEntity(entName, "sphere.mesh");
  entity->setCastShadows(true);
  
  Ogre::SceneNode *newNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(nodeName);
  newNode->attachObject(entity);

  mPhysics->addRigidSphere(entity, newNode, 0.1f, 1.0f, btVector3(0,0,0), btVector3(x,y,z), new btQuaternion(1.0f, 1.0f, 0, 0))->setLinearVelocity(btVector3(vx, vy, vz));

  // Change Entity Color
  Ogre::MaterialPtr mat = entity->getSubEntity(0)->getMaterial();
  Ogre::Pass *pass = mat->getTechnique(0)->getPass(0);
  pass->setDiffuse(0,1,0,0.1);
  pass->setSpecular(1,1,1,0.4);
  entity->setMaterialName(mat->getName());
}
Example #28
0
    Ogre::MaterialPtr
    IntersectGrid::_createIntersectGridMaterial(void)
    {
        String name = "IntersectGridMaterial";

        Ogre::ResourcePtr res = Ogre::MaterialManager::getSingleton().getByName(name);
        if (!res.isNull())
            return res;

        Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
       
        material->setLightingEnabled(false);
        material->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);
        material->setDepthWriteEnabled(false);
        // Use wireframe polygon mode
        material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME);

        return material;
    }
Example #29
0
void EffectManager::addEffect(const std::string &model, std::string textureOverride, const Ogre::Vector3 &worldPosition, float scale)
{
    Ogre::SceneNode* sceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(worldPosition);
    sceneNode->setScale(scale,scale,scale);

    NifOgre::ObjectScenePtr scene = NifOgre::Loader::createObjects(sceneNode, model);

    MWRender::Animation::setRenderProperties(scene, RV_Effects,
                        RQG_Main, RQG_Alpha, 0.f, false, NULL);

    for(size_t i = 0;i < scene->mControllers.size();i++)
    {
        if(scene->mControllers[i].getSource().isNull())
            scene->mControllers[i].setSource(Ogre::SharedPtr<EffectAnimationTime> (new EffectAnimationTime()));
    }

    if (!textureOverride.empty())
    {
        std::string correctedTexture = Misc::ResourceHelpers::correctTexturePath(textureOverride);
        for(size_t i = 0;i < scene->mParticles.size(); ++i)
        {
            Ogre::ParticleSystem* partSys = scene->mParticles[i];

            Ogre::MaterialPtr mat = scene->mMaterialControllerMgr.getWritableMaterial(partSys);

            for (int t=0; t<mat->getNumTechniques(); ++t)
            {
                Ogre::Technique* tech = mat->getTechnique(t);
                for (int p=0; p<tech->getNumPasses(); ++p)
                {
                    Ogre::Pass* pass = tech->getPass(p);
                    for (int tex=0; tex<pass->getNumTextureUnitStates(); ++tex)
                    {
                        Ogre::TextureUnitState* tus = pass->getTextureUnitState(tex);
                        tus->setTextureName(correctedTexture);
                    }
                }
            }
        }
    }

    mEffects.push_back(std::make_pair(sceneNode, scene));
}
Example #30
0
	void OgreModule::initEnd()
	{
		Ogre::CompositorManager2* compositorManager = mOgreRoot.getCompositorManager2();
		compositorManager->createBasicWorkspaceDef("Basic Workspace", Ogre::ColourValue(0.15f, 0.15f, 0.15f));
		compositorManager->createBasicWorkspaceDef("Black Workspace", Ogre::ColourValue::Black);

		Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
		Ogre::MaterialPtr material = materialManager->create("debug_invisible", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		material->setReceiveShadows(false);
		Ogre::Pass* pass = material->getTechnique(0)->getPass(0);
#if OGRE_VERSION_MAJOR == 2 && OGRE_VERSION_MINOR > 0
#else
		pass->setCullingMode(Ogre::CULL_NONE);
		pass->setColourWriteEnabled(false);
		pass->setDepthWriteEnabled(false);
#endif

		this->loadResources();
	}