void _makeOgre() { srand(time(0)); mRoot = new Ogre::Root("",""); mRoot->addFrameListener(this); #if 1 #ifdef _DEBUG mRoot->loadPlugin("RenderSystem_Direct3D9_d"); #else mRoot->loadPlugin("RenderSystem_Direct3D9"); #endif #else #ifdef _DEBUG mRoot->loadPlugin("RenderSystem_GL_d.dll"); #else mRoot->loadPlugin("RenderSystem_GL.dll"); #endif #endif mRoot->setRenderSystem(mRoot->getAvailableRenderers()[0]); Ogre::ResourceGroupManager* rgm = Ogre::ResourceGroupManager::getSingletonPtr(); rgm->addResourceLocation(".", "FileSystem"); mRoot->initialise(false); mWindow = mRoot->createRenderWindow("Monkey", 1024, 768, false); mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); mCamera = mSceneMgr->createCamera("Camera"); mViewport = mWindow->addViewport(mCamera); mViewport->setBackgroundColour(Gorilla::rgb(128, 70, 27)); rgm->initialiseAllResourceGroups(); }
//--------------------------------------------------------------------------------- bool CSkyxEditor::load(bool async) { if(mLoaded->get()) return true; Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr(); Ogre::String value = mOgitorsRoot->GetProjectFile()->getFileSystemName() + "::/SkyX/"; mngr->addResourceLocation(value, "Ofs", "SkyX"); mngr->initialiseResourceGroup("SkyX"); // Create SkyX mBasicController = new SkyX::BasicController(true); mHandle = new SkyX::SkyX(mOgitorsRoot->GetSceneManager(), mBasicController); mHandle->create(); mHandle->getVCloudsManager()->getVClouds()->registerCamera(mOgitorsRoot->GetViewport()->getCameraEditor()->getCamera()); mHandle->getVCloudsManager()->getVClouds()->setDistanceFallingParams(Ogre::Vector2(2, -1)); _restoreState(); registerForUpdates(); mLoaded->set(true); return true; }
void gkEngine::loadResources(const gkString& name) { if (name.empty()) return; try { Ogre::ConfigFile fp; fp.load(name); Ogre::ResourceGroupManager* resourceManager = Ogre::ResourceGroupManager::getSingletonPtr(); Ogre::ConfigFile::SectionIterator cit = fp.getSectionIterator(); while (cit.hasMoreElements()) { gkString elementname = cit.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap* ptr = cit.getNext(); for (Ogre::ConfigFile::SettingsMultiMap::iterator dit = ptr->begin(); dit != ptr->end(); ++dit) resourceManager->addResourceLocation(dit->second, dit->first, elementname); } Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); } catch (Ogre::Exception& e) { gkLogMessage("Engine: Failed to load resource file!\n" << e.getDescription()); } }
//----------------------------------------------------------------------------------------- void CTerrainGroupEditorFactory::addEditorResources(bool changeDefaultNames) { OgitorsRoot* ogitorsRoot = OgitorsRoot::getSingletonPtr(); Ogre::String terrainDir = ogitorsRoot->GetProjectOptions()->TerrainDirectory; // create Terrain project folder and folder to hold the terrain ogitorsRoot->GetProjectFile()->createDirectory(terrainDir.c_str()); ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/terrain/").c_str()); // copy default plant textures ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/plants/").c_str()); Ogre::String copydir = Ogitors::Globals::MEDIA_PATH + "/plants/"; OgitorsUtils::CopyDirOfs(copydir, (terrainDir+"/plants/").c_str()); // copy default terrain textures sorting them into two different folders ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/textures/").c_str()); ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/textures/diffusespecular").c_str()); ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/textures/normalheight").c_str()); Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr(); copydir = Ogitors::Globals::MEDIA_PATH + "/terrainTextures/"; mngr->addResourceLocation(copydir,"FileSystem","CopyTerrain"); Ogre::FileInfoListPtr resList = mngr->listResourceFileInfo("CopyTerrain"); // copy the files to the different directories OFS::OfsPtr& file = ogitorsRoot->GetProjectFile(); for (Ogre::FileInfoList::const_iterator it = resList->begin(); it != resList->end(); ++it) { Ogre::FileInfo fInfo = (*it); Ogre::String loc = copydir + fInfo.path + fInfo.filename; Ogre::String newName = fInfo.filename; if(fInfo.archive->getType() == "FileSystem") { if(fInfo.filename.find("diffusespecular") != -1) { /* since we're using different resource groups for the terrain lets remove the naming scheme from the filenames except if the project is being upgraded, in which case leave the name alone. */ if (changeDefaultNames) { newName = Ogre::StringUtil::replaceAll(newName, "_diffusespecular", ""); } OgitorsUtils::CopyFileOfs(loc, terrainDir+"/textures/diffusespecular/"+newName); } if(fInfo.filename.find("normalheight") != -1) { if (changeDefaultNames) { newName = Ogre::StringUtil::replaceAll(newName, "_normalheight", ""); } OgitorsUtils::CopyFileOfs(loc, terrainDir+"/textures/normalheight/"+newName); } } } resList.setNull(); ogitorsRoot->DestroyResourceGroup("CopyTerrain"); }
//-------------------------------------------------------------------------------------------------- CCaelumEditor::CCaelumEditor(CBaseEditorFactory *factory) : CBaseEditor(factory), _mUpdateCounter(0) { mHandle = 0; mSceneManager = 0; mName->init("CaelumSky"); Ogre::ResourceGroupManager *resmngr = Ogre::ResourceGroupManager::getSingletonPtr(); Ogre::String value = mOgitorsRoot->GetProjectFile()->getFileSystemName() + "::/" + mOgitorsRoot->GetProjectOptions()->CaelumDirectory + "/"; resmngr->addResourceLocation(value,"Ofs","Caelum"); resmngr->initialiseResourceGroup("Caelum"); }
bool OgreModel::init(Ogre::String meshName, Ogre::Vector3 pos, Ogre::Quaternion rot, Ogre::Vector3 scale, Ogre::SceneNode *levelRoot, Ogre::SceneManager *sceneManager, Ogre::String const &resourceGroupName ) { mSceneManager = sceneManager; // handle Ogre::ResourceGroupManager *rgm = Ogre::ResourceGroupManager::getSingletonPtr(); if(!rgm->resourceExists(resourceGroupName, meshName)) rgm->declareResource(meshName, "FileSystem", resourceGroupName); const bool withRestore = nullptr != mSceneNode; Ogre::Any any; if(withRestore) { any = mSceneNode->getUserObjectBindings().getUserAny(); if(mEntity != nullptr) { mEntity->detachFromParent(); mSceneManager->destroyEntity(mEntity); mEntity = nullptr; } if(mSceneNode != nullptr) { OgreUtils::destroySceneNode(mSceneNode); mSceneNode = nullptr; } } mEntity = sceneManager->createEntity(meshName); mSceneNode = levelRoot->createChildSceneNode(pos, rot); mSceneNode->attachObject(mEntity); mSceneNode->setInheritScale(false); mSceneNode->setScale(scale); if(withRestore) { mSceneNode->getUserObjectBindings().setUserAny(any); } return true; }
void SoundBank::openFile(std::string path, std::string id, int index) { std::string foundPath = path; Ogre::ResourceGroupManager* groupManager = Ogre::ResourceGroupManager::getSingletonPtr() ; Ogre::String group = groupManager->findGroupContainingResource(path) ; Ogre::FileInfoListPtr fileInfos = groupManager->findResourceFileInfo(group,foundPath); Ogre::FileInfoList::iterator it = fileInfos->begin(); if(it != fileInfos->end()) { foundPath = it->archive->getName() + "/" + foundPath; } else { foundPath = ""; } this->addSound(new SoundChunk(foundPath), id, index); }
std::string findFilePath(const std::string& filename) { // on demand init Model::initRessources() ; std::string foundPath = filename; Ogre::ResourceGroupManager* groupManager = Ogre::ResourceGroupManager::getSingletonPtr() ; Ogre::String group = groupManager->findGroupContainingResource(filename) ; Ogre::FileInfoListPtr fileInfos = groupManager->findResourceFileInfo(group,foundPath); Ogre::FileInfoList::iterator it = fileInfos->begin(); if(it != fileInfos->end()) { foundPath = it->archive->getName() + "/" + foundPath; foundPath; } else foundPath = ""; return foundPath; }
//----------------------------------------------------------------------------------------- CTerrainGroupEditor::CTerrainGroupEditor(CBaseEditorFactory *factory) : CBaseEditor(factory), mHandle(0), mBrushData(0), mModificationRect(0,0,0,0) { mDecalNode = 0; mDecalFrustum = 0; mEditMode = EM_NONE; mEditActive = false; mDecalTexture.setNull(); mBrushSize = 1; mName->init("Terrain Group"); mTextureGrass = "grass"; mBrushName = "AllWhite.png"; mMaxLayersAllowed = 6; Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr(); Ogre::String terrainDir = mOgitorsRoot->GetProjectFile()->getFileSystemName() + "::/" + mOgitorsRoot->GetProjectOptions()->TerrainDirectory + "/terrain"; mngr->addResourceLocation(terrainDir,"Ofs","TerrainResources"); mTerrainGlobalOptions = OGRE_NEW Ogre::TerrainGlobalOptions(); }
void _makeOgre() { srand(time(0)); mRoot = new Ogre::Root("",""); mRoot->addFrameListener(this); #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX mRoot->loadPlugin(OGRE_RENDERER); #else #if 1 #ifdef _DEBUG mRoot->loadPlugin("RenderSystem_Direct3D9_d"); #else mRoot->loadPlugin("RenderSystem_Direct3D9"); #endif #else #ifdef _DEBUG mRoot->loadPlugin("RenderSystem_GL_d.dll"); #else mRoot->loadPlugin("RenderSystem_GL.dll"); #endif #endif #endif mRoot->setRenderSystem(mRoot->getAvailableRenderers()[0]); Ogre::ResourceGroupManager* rgm = Ogre::ResourceGroupManager::getSingletonPtr(); rgm->addResourceLocation(".", "FileSystem"); mRoot->initialise(false); mWindow = mRoot->createRenderWindow("Gorilla - Press 0 to 9 for unit tests. C to Clear.", 1024, 768, false); mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); mCamera = mSceneMgr->createCamera("Camera"); mViewport = mWindow->addViewport(mCamera); mViewport->setBackgroundColour(Ogre::ColourValue::Black); rgm->initialiseAllResourceGroups(); }
void _makeOgre() { srand(time(0)); mRoot = new Ogre::Root("",""); mRoot->addFrameListener(this); #ifdef _DEBUG #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX // Change this to where ever you've squirrelled away your RenderSystem debug library mRoot->loadPlugin("/usr/local/lib/OGRE/RenderSystem_GL_d"); #else mRoot->loadPlugin("RenderSystem_Direct3D9_d"); #endif #else #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX // Change this to where ever you've squirrelled away your RenderSystem release library mRoot->loadPlugin("/usr/local/lib/OGRE/RenderSystem_GL"); #else mRoot->loadPlugin("RenderSystem_Direct3D9"); #endif #endif mRoot->setRenderSystem(mRoot->getAvailableRenderers()[0]); Ogre::ResourceGroupManager* rgm = Ogre::ResourceGroupManager::getSingletonPtr(); rgm->addResourceLocation(".", "FileSystem"); mRoot->initialise(false); mWindow = mRoot->createRenderWindow("Gorilla", 1024, 768, false); mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); mCamera = mSceneMgr->createCamera("Camera"); mViewport = mWindow->addViewport(mCamera); mViewport->setBackgroundColour(Gorilla::rgb(13, 13, 13)); rgm->initialiseAllResourceGroups(); }
//--------------------------------------------------------------------------------- bool CSkyxEditor::load(bool async) { if(mLoaded->get()) return true; Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr(); Ogre::String value = OgitorsUtils::QualifyPath(mOgitorsRoot->GetProjectOptions()->ProjectDir + "/SkyX"); mngr->addResourceLocation(value,"FileSystem","SkyX"); mngr->initialiseResourceGroup("SkyX"); // Create SkyX mHandle = new SkyX::SkyX(mOgitorsRoot->GetSceneManager(), mOgitorsRoot->GetViewport()->getCameraEditor()->getCamera()); mHandle->create(); mHandle->getVCloudsManager()->create(); _restoreState(); registerForUpdates(); mLoaded->set(true); return true; }
void OgreExporter_c::ExportLevel(const WadLevel_c &level, const WadFile_c &file) { this->ExportLevelMaterials(level, file); Ogre::DefaultHardwareBufferManager hardwareBufferManager; Ogre::ManualObject manualMesh(level.GetName()); const LineDef_s *lineDefs = level.GetLineDefs(); const size_t numLineDefs = level.GetNumLineDefs(); const SideDef_s *sideDefs = level.GetSideDefs(); const Sector_s *sectors = level.GetSectors(); const Vertex_s *vertices = level.GetVertices(); for(size_t i = 0;i < numLineDefs; ++i) { if(lineDefs[i].iLeftSideDef >= 0) { const SideDef_s &leftSide = sideDefs[lineDefs[i].iLeftSideDef]; const Sector_s &leftSideSector = sectors[leftSide.iSector]; const SideDef_s &rightSide = sideDefs[lineDefs[i].iRightSideDef]; const Sector_s &rightSideSector = sectors[rightSide.iSector]; if(leftSide.uMiddleTexture.uName != '-') { this->ExportWallMesh(manualMesh, leftSideSector.iFloorHeight, leftSideSector.iCeilHeight, leftSide.uMiddleTexture, leftSide.iOffsetX, leftSide.iOffsety, vertices, lineDefs[i], file); } if(leftSide.uLowerTexture.uName != '-') { this->ExportWallMesh(manualMesh, leftSideSector.iFloorHeight, leftSideSector.iFloorHeight, leftSide.uLowerTexture, leftSide.iOffsetX, leftSide.iOffsety, vertices, lineDefs[i], file); } if(leftSide.uUpperTexture.uName != '-') { this->ExportWallMesh(manualMesh, rightSideSector.iCeilHeight, leftSideSector.iCeilHeight, leftSide.uUpperTexture, leftSide.iOffsetX, leftSide.iOffsety, vertices, lineDefs[i], file); } } if(lineDefs[i].iRightSideDef >= 0) { const SideDef_s &rightSide = sideDefs[lineDefs[i].iRightSideDef]; const Sector_s &rightSideSector = sectors[rightSide.iSector]; if(rightSide.uLowerTexture.uName != '-') { const SideDef_s &leftSide = sideDefs[lineDefs[i].iLeftSideDef]; const Sector_s &leftSideSector = sectors[leftSide.iSector]; this->ExportWallMesh(manualMesh, rightSideSector.iFloorHeight, leftSideSector.iFloorHeight, rightSide.uLowerTexture, rightSide.iOffsetX, rightSide.iOffsety, vertices, lineDefs[i], file); } if(rightSide.uMiddleTexture.uName != '-') { this->ExportWallMesh(manualMesh, rightSideSector.iFloorHeight, rightSideSector.iCeilHeight, rightSide.uMiddleTexture, rightSide.iOffsetX, rightSide.iOffsety, vertices, lineDefs[i], file); } if(rightSide.uUpperTexture.uName != '-') { const SideDef_s &leftSide = sideDefs[lineDefs[i].iLeftSideDef]; const Sector_s &leftSideSector = sectors[leftSide.iSector]; this->ExportWallMesh(manualMesh, leftSideSector.iCeilHeight, rightSideSector.iCeilHeight, rightSide.uUpperTexture, rightSide.iOffsetX, rightSide.iOffsety, vertices, lineDefs[i], file); } } } namespace fs = boost::filesystem; fs::path path(strLevelDirectory); std::string levelName = level.GetName(); levelName += ".mesh"; path /= levelName; Ogre::LogManager logManager; logManager.createLog("ogre.log", true, true, false); Ogre::ResourceGroupManager resourceGroupManager; Ogre::MeshManager meshManager; Ogre::LodStrategyManager logStrategyManager; Ogre::MeshPtr mesh = manualMesh.convertToMesh(level.GetName()); Ogre::MeshSerializer serializer; serializer.exportMesh(mesh.get(), path.string()); mesh.setNull(); resourceGroupManager.shutdownAll(); this->CreateResourcesCfg(); }
bool Game::init() { try { // Read config first config.read("./config.cfg"); // Init SDL SDL_Init(SDL_INIT_VIDEO); SDL_putenv((char*)"SDL_VIDEO_CENTERED=true"); int flags = SDL_OPENGL; if (config.getFullscreen()) flags |= SDL_FULLSCREEN; SDL_SetVideoMode(config.getCanvasWidth(), config.getCanvasHeight(), config.getBits(), flags); SDL_WM_SetCaption("Yet Another Rubik's Cube", NULL); // Ogre root = new Ogre::Root(); #ifdef _WINDOWS root->loadPlugin("./RenderSystem_GL.dll"); #else root->loadPlugin("./RenderSystem_GL.so"); #endif Ogre::RenderSystem *rs = root->getRenderSystemByName("OpenGL Rendering Subsystem"); root->setRenderSystem(rs); rs->setConfigOption("Full Screen", config.getFullscreenStr()); rs->setConfigOption("Video Mode", config.getVideoModeStr()); root->initialise(false); // Window Ogre::NameValuePairList params; #ifdef _WINDOWS SDL_SysWMinfo info; SDL_VERSION(&info.version); SDL_GetWMInfo(&info); params["externalWindowHandle"] = Ogre::StringConverter::toString(reinterpret_cast<size_t>(info.window)); params["externalGLContent"] = Ogre::StringConverter::toString(reinterpret_cast<size_t>(info.hglrc)); params["externalGLControl"] = Ogre::String("True"); #else params["currentGLContext"] = Ogre::String("True"); #endif wnd = root->createRenderWindow("Main window", config.getCanvasWidth(), config.getCanvasHeight(), config.getFullscreen(), ¶ms); wnd->setVisible(true); // Input imgr = new InputManager(); // Hard-code res location Ogre::ResourceGroupManager *rgm = Ogre::ResourceGroupManager::getSingletonPtr(); rgm->addResourceLocation("res.gdat", "Zip", "General"); rgm->initialiseAllResourceGroups(); // Window and rendering events listener root->addFrameListener(this); imgr->regEventListener(this); imgr->regKeyboardListener(this); } catch (std::exception &e) { #ifdef _WINDOWS MessageBoxA(NULL, e.what(), "Exception occured", MB_OK | MB_ICONERROR); #else std::cout << e.what(); #endif return false; } return true; }
void _makeOgre() { srand(time(0)); mRoot = new Ogre::Root("",""); mRoot->addFrameListener(this); #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX mRoot->loadPlugin(OGRE_RENDERER); #else #if 1 #ifdef _DEBUG mRoot->loadPlugin("RenderSystem_Direct3D9_d"); #else mRoot->loadPlugin("RenderSystem_Direct3D9"); #endif #else #ifdef _DEBUG mRoot->loadPlugin("RenderSystem_GL_d.dll"); #else mRoot->loadPlugin("RenderSystem_GL.dll"); #endif #endif #endif mRoot->setRenderSystem(mRoot->getAvailableRenderers()[0]); Ogre::ResourceGroupManager* rgm = Ogre::ResourceGroupManager::getSingletonPtr(); rgm->addResourceLocation(".", "FileSystem"); mRoot->initialise(false); mWindow = mRoot->createRenderWindow("Gorilla", 1024, 768, false); mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); mCamera = mSceneMgr->createCamera("Camera"); mViewport = mWindow->addViewport(mCamera); Ogre::ColourValue BackgroundColour = Ogre::ColourValue(0.1337f, 0.1337f, 0.1337f, 1.0f); Ogre::ColourValue GridColour = Ogre::ColourValue(0.2000f, 0.2000f, 0.2000f, 1.0f); mViewport->setBackgroundColour(BackgroundColour); rgm->initialiseAllResourceGroups(); mCamera->setPosition(10,2,10); mCamera->lookAt(0,2,0); mCamera->setNearClipDistance(0.05f); mCamera->setFarClipDistance(1000); mReferenceObject = new Ogre::ManualObject("ReferenceGrid"); mReferenceObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST); Ogre::Real step = 1.0f; unsigned int count = 200; unsigned int halfCount = count / 2; Ogre::Real full = (step * count); Ogre::Real half = full / 2; Ogre::Real y = 0; Ogre::ColourValue c; for (unsigned i=0;i < count+1;i++) { if (i == halfCount) c = Ogre::ColourValue(0.5f,0.3f,0.3f,1.0f); else c = GridColour; mReferenceObject->position(-half,y,-half+(step*i)); mReferenceObject->colour(BackgroundColour); mReferenceObject->position(0,y,-half+(step*i)); mReferenceObject->colour(c); mReferenceObject->position(0,y,-half+(step*i)); mReferenceObject->colour(c); mReferenceObject->position(half,y,-half+(step*i)); mReferenceObject->colour(BackgroundColour); if (i == halfCount) c = Ogre::ColourValue(0.3f,0.3f,0.5f,1.0f); else c = GridColour; mReferenceObject->position(-half+(step*i),y,-half); mReferenceObject->colour(BackgroundColour); mReferenceObject->position(-half+(step*i),y,0); mReferenceObject->colour(c); mReferenceObject->position(-half+(step*i),y,0); mReferenceObject->colour(c); mReferenceObject->position(-half+(step*i),y, half); mReferenceObject->colour(BackgroundColour); } mReferenceObject->end(); mSceneMgr->getRootSceneNode()->attachObject(mReferenceObject); }
//----------------------------------------------------------------------------------------- bool CTerrainGroupEditor::load(bool async) { if(mLoaded->get()) return true; if(!getParent()->load()) return false; Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr(); Ogre::String terrainDir = OgitorsRoot::getSingletonPtr()->GetProjectOptions()->TerrainDirectory; terrainDir = mOgitorsRoot->GetProjectFile()->getFileSystemName() + "::/" + terrainDir + "/"; mngr->addResourceLocation(terrainDir + "textures/normalheight", "Ofs", "TerrainGroupNormalHeight"); mngr->initialiseResourceGroup("TerrainGroupNormalHeight"); mngr->addResourceLocation(terrainDir + "textures/diffusespecular", "Ofs", "TerrainGroupDiffuseSpecular"); mngr->initialiseResourceGroup("TerrainGroupDiffuseSpecular"); mngr->addResourceLocation(terrainDir + "plants", "Ofs", "TerrainGroupPlants"); mngr->initialiseResourceGroup("TerrainGroupPlants"); OgitorsRoot::getSingletonPtr()->PrepareTerrainResources(); OgitorsRoot::getSingletonPtr()->ReloadUserResources(); mDecalFrustum = OGRE_NEW Ogre::Frustum(); mDecalNode = getSceneManager()->getRootSceneNode()->createChildSceneNode("OgitorTerrainDecalNode"); mDecalNode->setPosition(99999, -99999, 99999); mDecalNode->attachObject(mDecalFrustum); mDecalFrustum->setProjectionType(Ogre::PT_ORTHOGRAPHIC); mDecalNode->setOrientation(Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_X)); mDecalFrustum->setFOVy(Ogre::Degree(45)); mDecalFrustum->setNearClipDistance(10); mDecalFrustum->setOrthoWindow(10, 10); mDecalFrustum->setVisible(false); mDecalTexture = Ogre::TextureManager::getSingletonPtr()->createManual("OgitorDecalTexture", "TerrainResources", Ogre::TEX_TYPE_2D, 256, 256, 1, 1, Ogre::PF_A8R8G8B8, Ogre::TU_DYNAMIC_WRITE_ONLY, this); mBrushData = OGRE_ALLOC_T(float, BRUSH_DATA_SIZE * BRUSH_DATA_SIZE, Ogre::MEMCATEGORY_GEOMETRY); mTerrainGlobalOptions->setMaxPixelError(mMaxPixelError->get()); mTerrainGlobalOptions->setCompositeMapSize(mCompositeMapTextureSize->get()); mTerrainGlobalOptions->setCompositeMapDistance(mCompositeMapDistance->get()); mTerrainGlobalOptions->setLightMapSize(mLightMapTextureSize->get()); mTerrainGlobalOptions->setLayerBlendMapSize(mBlendMapTextureSize->get()); mTerrainGlobalOptions->setUseVertexCompressionWhenAvailable(false); mTerrainGlobalOptions->setSkirtSize(mSkirtSize->get()); mTerrainGlobalOptions->setUseRayBoxDistanceCalculation(mUseRayBoxDistanceCalculation->get()); if(mMaterialGeneratorType->get() == 1) { Ogre::TerrainMaterialGeneratorPtr matGenPtr(OGRE_NEW Ogre::TerrainMaterialGeneratorC(this, mDecalFrustum)); mTerrainGlobalOptions->setDefaultMaterialGenerator(matGenPtr); mMaxLayersAllowed = 10; } else { Ogre::TerrainMaterialGeneratorPtr matGenPtr(OGRE_NEW Ogre::TerrainMaterialGeneratorB(this, mDecalFrustum)); mTerrainGlobalOptions->setDefaultMaterialGenerator(matGenPtr); mMaxLayersAllowed = 6; } CSceneManagerEditor *mSceneMgr = static_cast<CSceneManagerEditor*>(mOgitorsRoot->GetSceneManagerEditor()); if(mSceneMgr->getShadowsEnabled()) { if(mMaterialGeneratorType->get() == 1) { Ogre::TerrainMaterialGeneratorC::SM2Profile* matProfile = static_cast<Ogre::TerrainMaterialGeneratorC::SM2Profile*>(mTerrainGlobalOptions->getDefaultMaterialGenerator()->getActiveProfile()); matProfile->setReceiveDynamicShadowsEnabled(true); matProfile->setReceiveDynamicShadowsLowLod(false); matProfile->setReceiveDynamicShadowsDepth(true); matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(mSceneMgr->getPSSMSetup().get())); } else { Ogre::TerrainMaterialGeneratorB::SM2Profile* matProfile = static_cast<Ogre::TerrainMaterialGeneratorB::SM2Profile*>(mTerrainGlobalOptions->getDefaultMaterialGenerator()->getActiveProfile()); matProfile->setReceiveDynamicShadowsEnabled(true); matProfile->setReceiveDynamicShadowsLowLod(false); matProfile->setReceiveDynamicShadowsDepth(true); matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(mSceneMgr->getPSSMSetup().get())); } } CONNECT_PROPERTY_MEMFN(mSceneMgr, "shadows::enabled", CTerrainGroupEditor, onShadowsChange, mShadowsConnection[0]); CONNECT_PROPERTY_MEMFN(mSceneMgr, "shadows::technique", CTerrainGroupEditor, onShadowsTechniqueChange, mShadowsConnection[1]); mHandle = OGRE_NEW Ogre::TerrainGroup(mOgitorsRoot->GetSceneManager(), Ogre::Terrain::ALIGN_X_Z, mMapSize->get(), mWorldSize->get()); mHandle->setOrigin(Ogre::Vector3::ZERO); mHandle->setResourceGroup("TerrainResources"); mHandle->setFilenameConvention(mPageNamePrefix->get(), "ogt"); StaticGroupPtr = mHandle; mPGHandle = new PagedGeometry(mOgitorsRoot->GetViewport()->getCameraEditor()->getCamera(), mPGPageSize->get()); mPGHandle->addDetailLevel<GrassPage>(mPGDetailDistance->get()); //Create a GrassLoader object mGrassLoaderHandle = new GrassLoader(mPGHandle); mGrassLoaderHandle->setVisibilityFlags(1 << mLayer->get()); //Assign the "grassLoader" to be used to load geometry for the PagedGrass instance mPGHandle->setPageLoader(mGrassLoaderHandle); //Supply a height function to GrassLoader so it can calculate grass Y values mGrassLoaderHandle->setHeightFunction(OgitorTerrainGroupHeightFunction); Ogre::Vector3 vDir; Ogre::ColourValue cDiffuse; Ogre::SceneManager::MovableObjectIterator mit = mOgitorsRoot->GetSceneManager()->getMovableObjectIterator("Light"); while(mit.hasMoreElements()) { Ogre::Light *l = static_cast<Ogre::Light*>(mit.getNext()); if(l->getType() == Ogre::Light::LT_DIRECTIONAL && l->getCastShadows()) { vDir = l->getDerivedDirection(); cDiffuse = l->getDiffuseColour(); break; } } mTerrainGlobalOptions->setLightMapDirection(vDir); mTerrainGlobalOptions->setCompositeMapAmbient(mOgitorsRoot->GetSceneManager()->getAmbientLight()); mTerrainGlobalOptions->setCompositeMapDiffuse(cDiffuse); terrainDir = OgitorsRoot::getSingletonPtr()->GetProjectOptions()->TerrainDirectory + "/terrain/"; OFS::FileList TGAList = mOgitorsRoot->GetProjectFile()->listFiles(terrainDir.c_str(), OFS::OFS_FILE); for(unsigned int t = 0; t < TGAList.size(); t++) { int pos = TGAList[t].name.find("_density.tga"); if(pos > 0) { Ogre::Image _img; Ogre::String sLoc = terrainDir + TGAList[t].name; // Block to ensure streams are freed when exiting the block { OFS::OFSHANDLE *iHandle = new OFS::OFSHANDLE(); mOgitorsRoot->GetProjectFile()->openFile( *iHandle, sLoc.c_str() ); Ogre::DataStreamPtr img_stream = Ogre::DataStreamPtr(OGRE_NEW OfsDataStream(mOgitorsRoot->GetProjectFile(), iHandle)); _img.load(img_stream); } Ogre::String nLoc = terrainDir + TGAList[t].name.substr(0, pos); nLoc += "_density.png"; OgitorsUtils::SaveImageOfs( _img, nLoc ); mOgitorsRoot->GetProjectFile()->deleteFile( sLoc.c_str() ); } } registerForUpdates(); mLoaded->set(true); return true; }
bool CsBaseApplication::Init() { Ogre::String pluginsCfg; #ifdef _DEBUG pluginsCfg = "plugins_d.cfg"; #else pluginsCfg = "plugins.cfg"; #endif //create ogre root mRoot = new Ogre::Root(pluginsCfg); SetupResources(); Ogre::ResourceGroupManager *rgm = Ogre::ResourceGroupManager::getSingletonPtr(); // set a render system Ogre::RenderSystem* rSys; rSys = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem"); mRoot->setRenderSystem(rSys); // end gracelessly if the preferred renderer is not available if (mRoot->getRenderSystem() == NULL) { delete mRoot; return false; } // create a window mRoot->initialise(false); mWindow = mRoot->createRenderWindow( "CsWindow", // window name 1366, // window width, in pixels 768, // window height, in pixels false, // fullscreen or not 0); // use defaults for all other values Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this); // extra init Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); // Startup the GUI section ******************************************************* try { mRenderer = &CEGUI::OgreRenderer::bootstrapSystem(*mRoot->getRenderTarget("CsWindow")); } catch ( CEGUI::Exception& e) { MessageBoxA( NULL, e.getMessage().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); return false; } //CEGUI::OgreRenderer::bootstrapSystem(); CEGUI::Imageset::setDefaultResourceGroup("Imagesets"); CEGUI::Font::setDefaultResourceGroup("Fonts"); CEGUI::Scheme::setDefaultResourceGroup("Schemes"); CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel"); CEGUI::WindowManager::setDefaultResourceGroup("Layouts"); CEGUI::SchemeManager::getSingleton().create("TaharezLook.scheme"); CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow"); // ******************************************************************************* rgm->initialiseAllResourceGroups(); // SceneManager and viewports created in the GameInterface component CsAudioManager::Create(); mAudioManager = CsAudioManager::GetSingletonPtr(); mAudioManager->Init(); return true; }
void OgreSubsystem::_init() { if(!mInitialized) { Logger::getPtr()->logMessage("Ogre Subsystem starting up..."); mRoot = new Ogre::Root("",""); // suppress log output (TODO allow this to be redirected and enabled) //Ogre::LogManager::getSingleton().getDefaultLog()->setDebugOutputEnabled(false); //Ogre::LogManager::getSingleton().getDefaultLog()->setLogDetail(Ogre::LL_LOW); //#if (ORYX_PLATFORM == ORYX_PLATFORM_WIN32) //mRoot->loadPlugin("OgrePlugins/RenderSystem_GL.dll"); //mRoot->loadPlugin("OgrePlugins/Plugin_CgProgramManager.dll"); //mRoot->loadPlugin("OgrePlugins/Plugin_ParticleFX.dll"); //#else mRoot->loadPlugin("OgrePlugins/RenderSystem_GL"); //mRoot->loadPlugin("OgrePlugins/Plugin_CgProgramManager"); mRoot->loadPlugin("OgrePlugins/Plugin_ParticleFX"); //#endif Ogre::RenderSystem* rs = mRoot->getRenderSystemByName( "OpenGL Rendering Subsystem"); mRoot->setRenderSystem(rs); mRoot->initialise(false); Ogre::NameValuePairList miscP; miscP["vsync"] = "false"; miscP["FSAA"] = "0"; miscP["gamma"] = "false"; miscP["border"] = "fixed"; miscP["colourDepth"] = "32"; miscP["monitorIndex"] = "0"; for (std::map<String, String>::iterator it = mParams.begin(); it != mParams.end(); ++it) { miscP[it->first] = it->second; } mCurrentParams = mParams; mWindow = mRoot->createRenderWindow((getGfxParameter("window_name") != "") ? getGfxParameter("window_name") : "OryxEngine Application", mResolutionX,mResolutionY,mFullscreen,&miscP); mWindow->setActive(true); mSceneManager = mRoot->createSceneManager(Ogre::ST_GENERIC,"mSceneManager"); Ogre::SceneNode* defaultCamNode = mSceneManager->createSceneNode("DefaultCameraNode"); mDefaultCamera = new Camera("DefaultCamera",defaultCamNode,mSceneManager ->createCamera("DefaultCamera")); defaultCamNode->attachObject(mDefaultCamera->getCamera()); mDefaultCamera->setPosition(Vector3(0,0,0)); mDefaultCamera->getCamera()->setDirection(0,0,-1); mDefaultCamera->setFarClip(60); mDefaultCamera->setNearClip(0.1f); mDefaultCamera->setFOV(60.f); mViewport = mWindow->addViewport(mDefaultCamera->getCamera()); mViewport->setBackgroundColour(Ogre::ColourValue(1.0f,0.5f,0.2f)); mDefaultCamera->getCamera()->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight())); Ogre::ResourceGroupManager* resourceMgr = Ogre::ResourceGroupManager::getSingletonPtr(); resourceMgr->addResourceLocation("../media","FileSystem","General"); resourceMgr->addResourceLocation("../media/models","FileSystem","General"); resourceMgr->addResourceLocation("../media/materials","FileSystem","General"); resourceMgr->addResourceLocation("../media/textures","FileSystem","General"); resourceMgr->addResourceLocation("../media/audio","FileSystem","General"); resourceMgr->addResourceLocation("../media/gui","FileSystem","General"); resourceMgr->addResourceLocation("../media/scripts","FileSystem","General"); resourceMgr->addResourceLocation("../media/fonts","FileSystem","General"); resourceMgr->initialiseAllResourceGroups(); mRootSceneNode = new SceneNode(mSceneManager->getRootSceneNode()->getName(), mSceneManager->getRootSceneNode()); Logger::getPtr()->logMessage("Ogre Subsystem started up."); mInitialized = true; /*mSceneManager->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(new Ogre::LiSPSMShadowCameraSetup())); mSceneManager->setShadowTexturePixelFormat(Ogre::PF_FLOAT16_R); mSceneManager->setShadowTextureCasterMaterial("depthcaster"); mSceneManager->setShadowTextureSelfShadow(true); mSceneManager->setShadowTextureSize(512); mSceneManager->setShadowTextureCount(3); mSceneManager->setShadowCasterRenderBackFaces(false); mSceneManager->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);; mSceneManager->setShadowFarDistance(1000000.f);*/ } }