void Oculus::setCameras() { Ogre::Camera* camLeft = m_cameras[0] ; Ogre::Camera* camRight = m_cameras[1] ; Ogre::RenderTexture* renderTexLeft = mLeftEyeRenderTexture->getBuffer()->getRenderTarget(); std::cout << "[Rift] Adding viewport to left texture" << std::endl; m_viewports[0] = renderTexLeft->addViewport(m_cameras[0]); renderTexLeft->getViewport(0)->setOverlaysEnabled(true); std::cout << "[Rift] Adding viewport to right texture" << std::endl; Ogre::RenderTexture* renderTexRight = mRightEyeRenderTexture->getBuffer()->getRenderTarget(); m_viewports[1] = renderTexRight->addViewport(m_cameras[1]); renderTexRight->getViewport(0)->setOverlaysEnabled(true); m_viewports[0]->setBackgroundColour(g_defaultViewportColour); m_viewports[1]->setBackgroundColour(g_defaultViewportColour); ovrFovPort fovLeft = mHMD->DefaultEyeFov[ovrEye_Left]; ovrFovPort fovRight = mHMD->DefaultEyeFov[ovrEye_Right]; float combinedTanHalfFovHorizontal = std::max( fovLeft.LeftTan, fovLeft.RightTan ); float combinedTanHalfFovVertical = std::max( fovLeft.UpTan, fovLeft.DownTan ); float aspectRatio = combinedTanHalfFovHorizontal / combinedTanHalfFovVertical; m_cameras[0]->setAspectRatio( aspectRatio ); m_cameras[1]->setAspectRatio( aspectRatio ); ovrMatrix4f projL = ovrMatrix4f_Projection ( fovLeft, g_defaultNearClip, g_defaultFarClip, true ); ovrMatrix4f projR = ovrMatrix4f_Projection ( fovRight, g_defaultNearClip, g_defaultFarClip, true ); m_cameras[0]->setCustomProjectionMatrix( true, Ogre::Matrix4( projL.M[0][0], projL.M[0][1], projL.M[0][2], projL.M[0][3], projL.M[1][0], projL.M[1][1], projL.M[1][2], projL.M[1][3], projL.M[2][0], projL.M[2][1], projL.M[2][2], projL.M[2][3], projL.M[3][0], projL.M[3][1], projL.M[3][2], projL.M[3][3] ) ); m_cameras[1]->setCustomProjectionMatrix( true, Ogre::Matrix4( projR.M[0][0], projR.M[0][1], projR.M[0][2], projR.M[0][3], projR.M[1][0], projR.M[1][1], projR.M[1][2], projR.M[1][3], projR.M[2][0], projR.M[2][1], projR.M[2][2], projR.M[2][3], projR.M[3][0], projR.M[3][1], projR.M[3][2], projR.M[3][3] ) ); }
//------------------------------------------------------------------------------------------- void MagickWidget::loadMesh(Ogre::MeshPtr pMesh) { QString directory(OgitorsRoot::getSingletonPtr()->GetProjectOptions()->ProjectDir.c_str()); if(directory.isEmpty()) directory = "./"; QDir(directory).mkpath("entitycache"); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "MeshMagickTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8A8 , Ogre::TU_RENDERTARGET ); Ogre::RenderTexture *rttTex = texture->getBuffer()->getRenderTarget(); Ogre::SceneManager *mSceneMgr = Ogre::Root::getSingletonPtr()->createSceneManager("OctreeSceneManager", "MeshMagickTexMgr"); Ogre::Light *dirl = mSceneMgr->createLight("DisplayLight"); dirl->setDirection(-1,-1,-1); dirl->setDiffuseColour(1,1,1); dirl->setType(Ogre::Light::LT_DIRECTIONAL); Ogre::Camera* RTTCam = mSceneMgr->createCamera("MeshMagickCam"); RTTCam->setNearClipDistance(0.01F); RTTCam->setFarClipDistance(0); RTTCam->setAspectRatio(1); RTTCam->setFOVy(Ogre::Degree(90)); RTTCam->setPosition(0,0,1); RTTCam->lookAt(0,0,0); Ogre::Viewport *v = rttTex->addViewport( RTTCam ); v->setClearEveryFrame( true ); v->setBackgroundColour(Ogre::ColourValue(0,0,0)); Ogre::Entity *mEntity; mEntity = mSceneMgr->createEntity("scbDisplay", pMesh->getName()); mSceneMgr->getRootSceneNode()->attachObject(mEntity); Ogre::Vector3 vSize = mEntity->getBoundingBox().getHalfSize(); Ogre::Vector3 vCenter = mEntity->getBoundingBox().getCenter(); vSize += Ogre::Vector3(vSize.z, vSize.z, vSize.z); float maxsize = std::max(std::max(vSize.x,vSize.y),vSize.z); vSize = Ogre::Vector3(0, 0, maxsize * 1.15f) + vCenter; RTTCam->setPosition(vSize.x,vSize.y,vSize.z); RTTCam->lookAt(vCenter.x,vCenter.y,vCenter.z); rttTex->update(); Ogre::String imagefile = OgitorsUtils::QualifyPath(directory.toStdString() + "/entitycache/meshmagick.png"); rttTex->writeContentsToFile(imagefile); mEntity->detachFromParent(); mSceneMgr->destroyEntity(mEntity); rttTex->removeAllViewports(); Ogre::Root::getSingletonPtr()->destroySceneManager(mSceneMgr); mDisplayWidget->setImage(QString(imagefile.c_str())); }
void OgreRTTexture::begin() { Ogre::RenderTexture* rtt = mTexture->getBuffer()->getRenderTarget(); if (mViewport == nullptr) { mViewport = rtt->addViewport(nullptr); mViewport->setClearEveryFrame(false); mViewport->setOverlaysEnabled(false); } Ogre::RenderSystem* system = Ogre::Root::getSingleton().getRenderSystem(); system->_setProjectionMatrix(mProjectMatrix); mSaveViewport = system->_getViewport(); system->_setViewport(mViewport); system->clearFrameBuffer(Ogre::FBT_COLOUR, Ogre::ColourValue::ZERO); }
// ---------------------------------------------------------------- // sets up the ogre viewports and associates the appropriate // camera & render texture to each // ---------------------------------------------------------------- bool OgreOpenVR::initOgreViewports() { Ogre::RenderTexture* renderTex = m_ogreRenderTexture->getBuffer()->getRenderTarget(); // configure the two viewports to each render to half of the render targer // each half corresponds to one eye, and we submit both in one big texture to OpenVR m_viewports[0] = renderTex->addViewport(m_cameras[0], 0, 0.0f, 0.0f, 0.5f, 1.0f); m_viewports[1] = renderTex->addViewport(m_cameras[1], 1, 0.5f, 0.0f, 0.5f, 1.0f); renderTex->setAutoUpdated(true); m_viewports[0]->setBackgroundColour(Ogre::ColourValue(97 / 255.0f, 200 / 255.0f, 200 / 255.0f)); m_viewports[0]->setOverlaysEnabled(true); m_viewports[0]->setAutoUpdated(true); m_viewports[1]->setBackgroundColour(Ogre::ColourValue(97 / 255.0f, 200 / 255.0f, 200 / 255.0f)); m_viewports[1]->setOverlaysEnabled(true); m_viewports[1]->setAutoUpdated(true); Ogre::LogManager::getSingleton().logMessage(Ogre::LML_NORMAL, "OgreOpenVR: Setup RTT viewports for ogre OpenVR textures"); return true; }
void GUIManager::miniMap(){ Ogre::TexturePtr tex = mRoot->getTextureManager()->createManual( "RTT", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); Ogre::RenderTexture *rtex = tex->getBuffer()->getRenderTarget(); cam = mSceneMgr->createCamera("RearCam"); //Vector3 fool = Ogre::Vector3(1550,0,1250); cam->setPosition(1250, 300, 1000); //cam->lookAt(0,0,0); Ogre::Viewport *v = rtex->addViewport(cam); v->setOverlaysEnabled(false); v->setClearEveryFrame(true); v->setBackgroundColour(Ogre::ColourValue::Black); CEGUI::Texture &guiTex = mRenderer->createTexture(tex); CEGUI::Imageset &imageSet = CEGUI::ImagesetManager::getSingleton().create("RTTImageset", guiTex); imageSet.defineImage("RTTImage", CEGUI::Point(0.0f, 0.0f), CEGUI::Size(guiTex.getSize().d_width, guiTex.getSize().d_height), CEGUI::Point(0.0f, 0.0f)); mini_map = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "RTTWindow"); mini_map->setSize(CEGUI::UVector2(CEGUI::UDim(0.3f, 0),CEGUI::UDim(0.2f, 0))); mini_map->setPosition(CEGUI::UVector2(CEGUI::UDim(0.69f, 0),CEGUI::UDim(0.0f, 0))); mini_map->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imageSet.getImage("RTTImage"))); sheet->addChildWindow(mini_map); mini_map->setVisible(false); }
CRosRttTexture::CRosRttTexture(unsigned width, unsigned height, Ogre::Camera * camera, bool isDepth /*= false*/ ) : m_materialName("MyRttMaterial") , width_(width) , height_(height) , frame_("/map") , m_bIsDepth( isDepth ) { assert( height > 0 && width > 0 ); { // Set encoding current_image_.encoding = ROS_IMAGE_FORMAT; // Set image size current_image_.width = width; current_image_.height = height; // Set image row length in bytes (row length * 3 bytes for a color) current_image_.step = width * BPP; #if OGRE_ENDIAN == ENDIAN_BIG current_image_.is_bigendian = true; #else current_image_.is_bigendian = false; #endif // Resize data current_image_.data.resize( width_ * height_ * BPP); } Ogre::TextureManager & lTextureManager( Ogre::TextureManager::getSingleton() ); Ogre::String textureName("RVIZ_CamCast_Texture"); bool lGammaCorrection( false ); unsigned int lAntiAliasing( 0 ); unsigned int lNumMipmaps( 0 ); if( isDepth ) { texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, lNumMipmaps, OGRE_DEPTH_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing); } else { texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, lNumMipmaps, OGRE_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing); } // Create render target Ogre::RenderTexture* lRenderTarget = NULL; Ogre::HardwarePixelBufferSharedPtr lRttBuffer = texture_->getBuffer(); lRenderTarget = lRttBuffer->getRenderTarget(); lRenderTarget->setAutoUpdated(true); // Create and attach viewport Ogre::Viewport* lRttViewport1 = lRenderTarget->addViewport(camera, 50, 0.00f, 0.00f, 1.0f, 1.0f); lRttViewport1->setAutoUpdated(true); Ogre::ColourValue lBgColor1(0.0,0.0,0.0,1.0); lRttViewport1->setBackgroundColour(lBgColor1); // create a material using this texture. //Get a reference on the material manager, which is a singleton. Ogre::MaterialManager& lMaterialManager = Ogre::MaterialManager::getSingleton(); Ogre::MaterialPtr lMaterial = lMaterialManager.create(m_materialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::Technique * lTechnique = lMaterial->getTechnique(0); Ogre::Pass* lPass = lTechnique->getPass(0); if( isDepth ) { lPass->setLightingEnabled(false); } Ogre::TextureUnitState* lTextureUnit = lPass->createTextureUnitState(); lTextureUnit->setTextureName(textureName); lTextureUnit->setNumMipmaps(0); lTextureUnit->setTextureFiltering(Ogre::TFO_BILINEAR); update(); }
void RenderedTexture::renderTextures() { //Set up RTT texture Ogre::TexturePtr renderTexture; if (renderTexture.isNull()) { renderTexture = Ogre::TextureManager::getSingleton().createManual( getUniqueID("RenderedEntityMaterial"), "EntityRenderer", Ogre::TEX_TYPE_2D, textureSize, textureSize, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET, 0); } renderTexture->setNumMipmaps(0); //Set up render target Ogre::RenderTexture* renderTarget = renderTexture->getBuffer()->getRenderTarget(); renderTarget->setAutoUpdated(false); //Set up camera Ogre::SceneNode* camNode = sceneMgr->getSceneNode("EntityRenderer::cameraNode"); Ogre::Camera* renderCamera = sceneMgr->createCamera(getUniqueID("EntityRendererCam")); camNode->attachObject(renderCamera); renderCamera->setLodBias(1000.0f); Ogre::Viewport* renderViewport = renderTarget->addViewport(renderCamera); renderViewport->setOverlaysEnabled(false); renderViewport->setClearEveryFrame(true); renderViewport->setShadowsEnabled(false); renderViewport->setBackgroundColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 0.0f)); //Set up scene node Ogre::SceneNode* node = sceneMgr->getSceneNode("EntityRenderer::renderNode"); Ogre::SceneNode* oldSceneNode = entity->getParentSceneNode(); if (oldSceneNode) oldSceneNode->detachObject(entity); node->attachObject(entity); node->setPosition(-entityCenter); //Set up camera FOV const Ogre::Real objDist = entityRadius * 100; const Ogre::Real nearDist = objDist - (entityRadius + 1); const Ogre::Real farDist = objDist + (entityRadius + 1); renderCamera->setAspectRatio(1.0f); renderCamera->setFOVy(Ogre::Math::ATan(2.0 * entityRadius / objDist)); renderCamera->setNearClipDistance(nearDist); renderCamera->setFarClipDistance(farDist); //Disable mipmapping (without this, masked textures look bad) Ogre::MaterialManager* mm = Ogre::MaterialManager::getSingletonPtr(); Ogre::FilterOptions oldMinFilter = mm->getDefaultTextureFiltering(Ogre::FT_MIN); Ogre::FilterOptions oldMagFilter = mm->getDefaultTextureFiltering(Ogre::FT_MAG); Ogre::FilterOptions oldMipFilter = mm->getDefaultTextureFiltering(Ogre::FT_MIP); mm->setDefaultTextureFiltering(Ogre::FO_POINT, Ogre::FO_LINEAR,Ogre:: FO_NONE); //Disable fog Ogre::FogMode oldFogMode = sceneMgr->getFogMode(); Ogre::ColourValue oldFogColor = sceneMgr->getFogColour(); Ogre::Real oldFogDensity = sceneMgr->getFogDensity(); Ogre::Real oldFogStart = sceneMgr->getFogStart(); Ogre::Real oldFogEnd = sceneMgr->getFogEnd(); sceneMgr->setFog(Ogre::FOG_NONE); // Get current status of the queue mode Ogre::SceneManager::SpecialCaseRenderQueueMode OldSpecialCaseRenderQueueMode = sceneMgr->getSpecialCaseRenderQueueMode(); //Only render the entity sceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_INCLUDE); sceneMgr->addSpecialCaseRenderQueue(renderQueueGroup); Ogre::uint8 oldRenderQueueGroup = entity->getRenderQueueGroup(); entity->setRenderQueueGroup(renderQueueGroup); bool oldVisible = entity->getVisible(); entity->setVisible(true); float oldMaxDistance = entity->getRenderingDistance(); entity->setRenderingDistance(0); //Calculate the filename hash used to uniquely identity this render std::string strKey = entityKey; char key[32] = {0}; Ogre::uint32 i = 0; for (std::string::const_iterator it = entityKey.begin(); it != entityKey.end(); ++it) { key[i] ^= *it; i = (i+1) % sizeof(key); } for (i = 0; i < sizeof(key); ++i) key[i] = (key[i] % 26) + 'A'; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( GetUserDir().string(), "FileSystem", "BinFolder"); std::string fileNamePNG = "Rendered." + std::string(key, sizeof(key)) + '.' + Ogre::StringConverter::toString(textureSize) + ".png"; //Attempt to load the pre-render file if allowed bool needsRegen = false; if (!needsRegen) { try{ texture = Ogre::TextureManager::getSingleton().load( fileNamePNG, "BinFolder", Ogre::TEX_TYPE_2D, 0); } catch (...) { needsRegen = true; } } if (needsRegen) { //If this has not been pre-rendered, do so now //Position camera camNode->setPosition(0, 0, 0); // TODO camNode->setOrientation(Quaternion(yaw, Vector3::UNIT_Y) * Quaternion(-pitch, Vector3::UNIT_X)); camNode->translate(Ogre::Vector3(0, 0, objDist), Ogre::Node::TS_LOCAL); renderTarget->update(); //Save RTT to file renderTarget->writeContentsToFile((GetUserDir() / fileNamePNG).string()); //Load the render into the appropriate texture view texture = Ogre::TextureManager::getSingleton().load(fileNamePNG, "BinFolder", Ogre::TEX_TYPE_2D, 0); ggTexture = ClientUI::GetTexture(GetUserDir() / fileNamePNG); } entity->setVisible(oldVisible); entity->setRenderQueueGroup(oldRenderQueueGroup); entity->setRenderingDistance(oldMaxDistance); sceneMgr->removeSpecialCaseRenderQueue(renderQueueGroup); // Restore original state sceneMgr->setSpecialCaseRenderQueueMode(OldSpecialCaseRenderQueueMode); //Re-enable mipmapping mm->setDefaultTextureFiltering(oldMinFilter, oldMagFilter, oldMipFilter); //Re-enable fog sceneMgr->setFog(oldFogMode, oldFogColor, oldFogDensity, oldFogStart, oldFogEnd); //Delete camera renderTarget->removeViewport(0); renderCamera->getSceneManager()->destroyCamera(renderCamera); //Delete scene node node->detachAllObjects(); if (oldSceneNode) oldSceneNode->attachObject(entity); //Delete RTT texture assert(!renderTexture.isNull()); std::string texName2(renderTexture->getName()); renderTexture.setNull(); if (Ogre::TextureManager::getSingletonPtr()) Ogre::TextureManager::getSingleton().remove(texName2); }
int EnvironmentCoreApplication::startLoop(std::function<int()> _func) { int l_run = 0; isRunning = true; double l_systemTimeIncriment = 0.0; int l_frame = 0; Ogre::TexturePtr rtt_texture = Ogre::TextureManager::getSingleton().createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, m_pRenderWindow->getWidth(), m_pRenderWindow->getHeight(), 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); Ogre::RenderTexture* renderTexture = rtt_texture->getBuffer()->getRenderTarget(); renderTexture->addViewport(m_pCamera); renderTexture->getViewport(0)->setClearEveryFrame(true); renderTexture->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black); renderTexture->getViewport(0)->setOverlaysEnabled(false); std::chrono::high_resolution_clock l_time; auto l_start = l_time.now(); auto l_last = l_start; while (l_run == 0) { try { m_pChSystem->DoFrameDynamics((l_systemTimeIncriment / 2.0)); } catch (std::exception e) { } try { m_pChSystem->DoFrameDynamics((l_systemTimeIncriment / 2.0)); } catch (std::exception e) { } m_pInputManager->update(); if (m_pInputManager->WindowClose) { l_run++; break; } m_pGUIManager->update(); l_run = _func(); m_pScene->update(); m_pViewport->update(); m_pRenderWindow->update(false); m_pRenderWindow->swapBuffers(); m_pRoot->renderOneFrame(); m_pCamera->setAspectRatio((((float)(m_pViewport->getActualWidth())) / ((float)(m_pViewport->getActualHeight())))); if (!isRealTime) { l_systemTimeIncriment += timestep_max; timestep = timestep_max; } else { l_systemTimeIncriment = ((double)(std::chrono::duration_cast<std::chrono::milliseconds>(l_time.now() - l_start).count())) / 1000.0; //converts standard library time difference to a double for Chrono l_systemTimeIncriment = l_systemTimeIncriment > timestep_max ? l_systemTimeIncriment+=timestep_max : l_systemTimeIncriment; l_systemTimeIncriment = l_systemTimeIncriment < timestep_min ? l_systemTimeIncriment+=timestep_min : l_systemTimeIncriment; timestep = ((double)(std::chrono::duration_cast<std::chrono::milliseconds>(l_time.now() - l_last).count())) / 1000.0; l_last = l_time.now(); } if (WriteToFile) { std::string name = "out/frame" + std::to_string(l_frame) + "time" + std::to_string(l_systemTimeIncriment) + ".png"; renderTexture->update(); renderTexture->writeContentsToFile(name); l_frame++; } Ogre::WindowEventUtilities::messagePump(); } isRunning = false; return l_run; }
CFakeObjectEntityManager::FakeObjectMap::iterator CFakeObjectEntityManager::_GetFakeNode(LPCTSTR szNodeName, tEntityNode* pNode, LPCTSTR szCameraName, int nTexWidth, int nTexHeight, LPCTSTR szBackgroundName) { //缺省摄像机的位置 static const float s_fHeight = 0.8f; static const float s_fDistance = 3.2f; static const float s_fPitch = 0.21f; FakeObjectMap::iterator it = m_mapObject.find(szNodeName); if(it != m_mapObject.end()) return it; //不存在,创建 FakeObject newNode; newNode.strName = szNodeName; //-------------------------------------------------- //创建RenderTarget Ogre::TexturePtr ptrTex = Ogre::TextureManager::getSingleton().createManual( Ogre::String(szNodeName) + "_RenderTexture", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, nTexWidth, nTexHeight, 1, 0, Ogre::PF_R8G8B8A8, Ogre::TU_RENDERTARGET, 0); //ptrTex->load(); newNode.ptrRenderTexture = ptrTex; Ogre::RenderTexture* pTexture = ptrTex->getBuffer()->getRenderTarget(); //缺省不刷新 pTexture->setAutoUpdated(false); pTexture->addListener(&g_theListener); //-------------------------------------------------- //放置摄像机 Ogre::SceneManager* pScnManager = CEngineInterface::GetMe()->GetFairySystem()->getSceneManager(); newNode.pCamera = pScnManager->createCamera(Ogre::String(szNodeName) + "_Camera"); //放缩系数 fVector3 fvScale = CEngineInterface::GetMe()->GetSacle(); newNode.fCameraHeight=s_fHeight; newNode.fCameraDistance=s_fDistance; newNode.fCameraPitch=s_fPitch; STRING szUserCameraValue; pNode->Actor_GetObjectProperty(szCameraName, szUserCameraValue); // if(szUserCameraValue.size() > 2 && szUserCameraValue.find(';') != STRING::npos) // { // sscanf(szUserCameraValue.c_str(), "%f;%f", &(newNode.fCameraHeight), &(newNode.fCameraDistance)); // } int Row_Index; Row_Index = atoi(szUserCameraValue.c_str()); const tDataBase* pDBC = g_pDataBase->GetDataBase(DBC_MODEL_PARAMETER); KLAssert(pDBC); const _DBC_MODEL_PARAMETER* pParameter = NULL; pParameter = (const _DBC_MODEL_PARAMETER*)((tDataBase*)pDBC)->Search_Index_EQU(Row_Index); if(pParameter) { newNode.fCameraHeight = pParameter->nHeight; newNode.fCameraDistance = pParameter->nDistance; } //设置摄像机 _UpdateCamera(newNode); newNode.pCamera->setNearClipDistance(10.f); newNode.pCamera->setAspectRatio((float)nTexWidth/nTexHeight); newNode.pCamera->setFOVy(Ogre::Degree(45.0f)); // 经验值 newNode.pCamera->setProjectionType(Ogre::PT_PERSPECTIVE); //透视投影 (平行投影 Ogre::PT_ORTHOGRAPHIC) //-------------------------------------------------- //创建ViewPort newNode.pViewPort = pTexture->addViewport(newNode.pCamera, 1); newNode.pViewPort->setClearEveryFrame(true); newNode.pViewPort->setBackgroundColour(Ogre::ColourValue(0,0,0,0)); newNode.pViewPort->setOverlaysEnabled(false); newNode.pViewPort->setSkiesEnabled(false); newNode.pViewPort->setShadowsEnabled(false); //-------------------------------------------------- //创建rectangle(如果纹理名称不为空并且所需的material template存在) Ogre::String backgroundTexName(szBackgroundName); Ogre::MaterialPtr originMat = Ogre::MaterialManager::getSingleton().getByName("UIModelBackground"); if (false == backgroundTexName.empty() && false == originMat.isNull()) { newNode.pRectange = new Ogre::Rectangle2D(true); newNode.pRectange->setCorners(-1.0f, 1.0f, 1.0f, -1.0f); Ogre::String cloneMatName = Ogre::String(szNodeName) + "_Rectangle"; Ogre::MaterialPtr cloneMat = Ogre::MaterialManager::getSingleton().getByName(cloneMatName); if (cloneMat.isNull()) { cloneMat = originMat->clone(cloneMatName); if (cloneMat->getNumTechniques()) { Ogre::Technique* tech = cloneMat->getTechnique(0); if (tech->getNumPasses()) { Ogre::Pass* pass = tech->getPass(0); if (pass->getNumTextureUnitStates()) { Ogre::TextureUnitState* tex = pass->getTextureUnitState(0); tex->setTextureName(szBackgroundName); } } } } newNode.pRectange->setMaterial(cloneMat->getName()); newNode.pRectange->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND); newNode.pRectange->setVisibilityFlags(Fairy::OVF_GUI_ELEMENTS); // 设置boundingbox为无限大,以防被camera剔除掉(默认的包围盒大小为-1,1) newNode.pRectange->setBoundingBox( Ogre::AxisAlignedBox( Ogre::Vector3(Ogre::Math::NEG_INFINITY, Ogre::Math::NEG_INFINITY, Ogre::Math::NEG_INFINITY), Ogre::Vector3(Ogre::Math::POS_INFINITY, Ogre::Math::POS_INFINITY, Ogre::Math::POS_INFINITY) ) ); Ogre::SceneNode* parentNode = CEngineInterface::GetMe()->GetFairySystem()->getBaseSceneNode()->createChildSceneNode(); parentNode->attachObject(newNode.pRectange); } //-------------------------------------------------- //加入Map m_mapObject.insert(std::make_pair(newNode.strName, newNode)); it = m_mapObject.find(newNode.strName); KLAssert(it != m_mapObject.end()); //加入索引Map m_mapIndexOfViewPort.insert(std::make_pair(newNode.pViewPort, &(it->second))); return it; }
void ZoneListWidget::_createImages(ImageMap& retlist) { retlist.clear(); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "EntityTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 256, 256, 0, Ogre::PF_A8R8G8B8 , Ogre::TU_RENDERTARGET ); Ogre::RenderTexture *rttTex = texture->getBuffer()->getRenderTarget(); Ogre::SceneManager *mSceneMgr = Ogre::Root::getSingletonPtr()->createSceneManager("OctreeSceneManager", "EntityTexMgr"); Ogre::Light *dirl = mSceneMgr->createLight("DisplayLight"); dirl->setDirection(-1,-1,-1); dirl->setDiffuseColour(1,1,1); dirl->setType(Ogre::Light::LT_DIRECTIONAL); Ogre::Camera* RTTCam = mSceneMgr->createCamera("EntityCam"); RTTCam->setNearClipDistance(0.01F); RTTCam->setFarClipDistance(0); RTTCam->setAspectRatio(1); RTTCam->setFOVy(Ogre::Degree(90)); RTTCam->setPosition(0,0,1); RTTCam->lookAt(0,0,0); Ogre::Viewport *v = rttTex->addViewport( RTTCam ); v->setClearEveryFrame( true ); v->setBackgroundColour(Ogre::ColourValue(0,0,0,0)); ModularZoneFactory* factory = dynamic_cast<ModularZoneFactory*>(OgitorsRoot::getSingletonPtr()->GetEditorObjectFactory("Modular Zone Object")); if(!factory)return; factory->loadZoneTemplates(); ZoneInfoMap zoneTemplates = factory->getZoneTemplateMap(); Ogre::Entity *mEntity; unsigned char dataptr[300 * 300 * 6]; unsigned char *dataptr2; Ogre::PixelBox pb(256,256,1,Ogre::PF_A8R8G8B8, dataptr); EntityMap entities; ZoneInfoMap::iterator zi; for(zi=zoneTemplates.begin();zi!=zoneTemplates.end();++zi) { Ogre::String addstr = (*zi).second.mMesh; if(entities.find((*zi).first) == entities.end()) entities.insert(EntityMap::value_type((*zi).first,addstr)); } EntityMap::const_iterator ite = entities.begin(); while(ite != entities.end()) { Ogre::String addstr = ite->second; mEntity = mSceneMgr->createEntity("MZP_Preview", addstr); mSceneMgr->getRootSceneNode()->attachObject(mEntity); //TODO: It would be nice to retrieve a Preview Camera Position from //the .zone file //TODO: also render portal outlines clearly so that the user can see //how the zone is laid out Ogre::Vector3 vSize = mEntity->getBoundingBox().getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_TOP);//.getHalfSize();//============ Ogre::Vector3 vCenter = mEntity->getBoundingBox().getCenter(); //FIXME ------ NICE PREVIEWS NEEDED - bigger vSize += Ogre::Vector3(vSize.z, vSize.z, vSize.z); float maxsize = std::max(std::max(vSize.x,vSize.y),vSize.z); //vSize = Ogre::Vector3(0, 0, maxsize * 1.1f) + vCenter; vSize = Ogre::Vector3(maxsize * 0.5f, vSize.y, maxsize * 0.5f) + vCenter; //vSize.x +=vSize.x/2;//Maybe test to see which is larger x/2 or z/2 and use that? //vSize.z +=vSize.x/2; //RTTCam->setProjectionType(Ogre::PT_ORTHOGRAPHIC); RTTCam->setPosition(vSize.x,vSize.y,vSize.z); RTTCam->lookAt(vCenter.x,vCenter.y,vCenter.z); rttTex->update(); rttTex->copyContentsToMemory(pb, Ogre::RenderTarget::FB_FRONT); dataptr2 = new unsigned char[96 * 96 * 4]; Ogre::PixelBox pb2(96,96,1,Ogre::PF_A8R8G8B8, dataptr2); Ogre::Image::scale(pb,pb2); addstr.erase(addstr.length() - 5, 5); retlist.insert(ImageMap::value_type((*ite).first, dataptr2)); mEntity->detachFromParent(); mSceneMgr->destroyEntity(mEntity); ite++; } rttTex->removeAllViewports(); Ogre::Root::getSingletonPtr()->destroySceneManager(mSceneMgr); Ogre::TextureManager::getSingletonPtr()->unload(texture->getName()); Ogre::TextureManager::getSingletonPtr()->remove(texture->getName()); }
int OgreOculus::go(void) { // Create Root object root = new Ogre::Root("plugin.cfg", "ogre.cfg"); // OpenGL root->loadPlugin("RenderSystem_GL_d"); root->setRenderSystem(root->getRenderSystemByName("OpenGL Rendering Subsystem")); // Initialize Root root->initialise(false); // Initialize Oculus ovrHmd hmd; ovrHmdDesc hmdDesc; ovrGraphicsLuid luid; ovr_Initialize(nullptr); if(ovr_Create(&hmd, &luid) != ovrSuccess) exit(-1); hmdDesc = ovr_GetHmdDesc(hmd); if(ovr_ConfigureTracking(hmd, ovrTrackingCap_Orientation |ovrTrackingCap_MagYawCorrection |ovrTrackingCap_Position, 0) != ovrSuccess) exit(-2); // Turn off HUD ovr_SetInt(hmd, "PerfHudMode", ovrPerfHud_Off); // Create a window window = root->createRenderWindow("Ogre + Oculus = <3", hmdDesc.Resolution.w/2, hmdDesc.Resolution.h/2, false); // Create scene manager and cameras smgr = root->createSceneManager(Ogre::ST_GENERIC); // Load Ogre resource paths from config file Ogre::ConfigFile cf; cf.load("resources_d.cfg"); // Go through all sections & settings in the file and add resources Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); Ogre::String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } // Set resources Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // Create the model itself via OgreModel.cpp createOgreModel(smgr); // Create camera createCamera(); // Set viewport and background color Ogre::Viewport* vp = window->addViewport(mCamera); vp->setBackgroundColour(Ogre::ColourValue(34, 89, 0)); // Yellow // Set aspect ratio mCamera->setAspectRatio( Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); // Initialize glew if(glewInit() != GLEW_OK) exit(-3); // Get texture sizes ovrSizei texSizeL, texSizeR; texSizeL = ovr_GetFovTextureSize(hmd, ovrEye_Left, hmdDesc.DefaultEyeFov[left], 1); texSizeR = ovr_GetFovTextureSize(hmd, ovrEye_Right, hmdDesc.DefaultEyeFov[right], 1); // Calculate render buffer size ovrSizei bufferSize; bufferSize.w = texSizeL.w + texSizeR.w; bufferSize.h = max(texSizeL.h, texSizeR.h); // Create render texture set ovrSwapTextureSet* textureSet; if(ovr_CreateSwapTextureSetGL(hmd, GL_RGB, bufferSize.w, bufferSize.h, &textureSet) != ovrSuccess) exit(-4); // Create Ogre render texture Ogre::GLTextureManager* textureManager = static_cast<Ogre::GLTextureManager*>(Ogre::GLTextureManager::getSingletonPtr()); Ogre::TexturePtr rtt_texture(textureManager->createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, bufferSize.w, bufferSize.h, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET)); Ogre::RenderTexture* rttEyes = rtt_texture->getBuffer(0, 0)->getRenderTarget(); Ogre::GLTexture* gltex = static_cast<Ogre::GLTexture*>(Ogre::GLTextureManager::getSingleton().getByName("RttTex").getPointer()); GLuint renderTextureID = gltex->getGLID(); // Put camera viewport on the ogre render texture Ogre::Viewport* vpts[nbEyes]; vpts[left]=rttEyes->addViewport(cams[left], 0, 0, 0, 0.5f); vpts[right]=rttEyes->addViewport(cams[right], 1, 0.5f, 0, 0.5f); vpts[left]->setBackgroundColour(Ogre::ColourValue(34, 89, 0)); // Black background vpts[right]->setBackgroundColour(Ogre::ColourValue(34, 89, 0)); ovrTexture* mirrorTexture; if(ovr_CreateMirrorTextureGL(hmd, GL_RGB, hmdDesc.Resolution.w, hmdDesc.Resolution.h, &mirrorTexture) != ovrSuccess) exit(-5); Ogre::TexturePtr mirror_texture(textureManager->createManual("MirrorTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, hmdDesc.Resolution.w, hmdDesc.Resolution.h, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET)); // Get GLIDs GLuint ogreMirrorTextureID = static_cast<Ogre::GLTexture*>(Ogre::GLTextureManager::getSingleton().getByName("MirrorTex").getPointer())->getGLID(); GLuint oculusMirrorTextureID = ((ovrGLTexture*)mirrorTexture)->OGL.TexId; // Create EyeRenderDesc ovrEyeRenderDesc EyeRenderDesc[nbEyes]; EyeRenderDesc[left] = ovr_GetRenderDesc(hmd, ovrEye_Left, hmdDesc.DefaultEyeFov[left]); EyeRenderDesc[right] = ovr_GetRenderDesc(hmd, ovrEye_Right, hmdDesc.DefaultEyeFov[right]); // Get offsets ovrVector3f offset[nbEyes]; offset[left]=EyeRenderDesc[left].HmdToEyeViewOffset; offset[right]=EyeRenderDesc[right].HmdToEyeViewOffset; // Compositor layer ovrLayerEyeFov layer; layer.Header.Type = ovrLayerType_EyeFov; layer.Header.Flags = 0; layer.ColorTexture[left] = textureSet; layer.ColorTexture[right] = textureSet; layer.Fov[left] = EyeRenderDesc[left].Fov; layer.Fov[right] = EyeRenderDesc[right].Fov; layer.Viewport[left] = OVR::Recti(0, 0, bufferSize.w/2, bufferSize.h); layer.Viewport[right] = OVR::Recti(bufferSize.w/2, 0, bufferSize.w/2, bufferSize.h); // Get projection matrices for(size_t eyeIndex(0); eyeIndex < ovrEye_Count; eyeIndex++) { // Get the projection matrix OVR::Matrix4f proj = ovrMatrix4f_Projection(EyeRenderDesc[eyeIndex].Fov, static_cast<float>(0.01f), 4000, true); // Convert it to Ogre matrix Ogre::Matrix4 OgreProj; for(size_t x(0); x < 4; x++) for(size_t y(0); y < 4; y++) OgreProj[x][y] = proj.M[x][y]; // Set the matrix cams[eyeIndex]->setCustomProjectionMatrix(true, OgreProj); } // Variables for render loop bool render(true); ovrFrameTiming hmdFrameTiming; ovrTrackingState ts; OVR::Posef pose; ovrLayerHeader* layers; // Create event listener for handling user input createEventListener(); //Run physics loop in a new thread std::map<Ogre::Entity*, Ogre::Vector3> positionRequests; std::map<Ogre::Entity*, std::string> animationRequests; std::map<Ogre::Entity*, std::vector<int>> rotationRequests; std::map<std::string, std::string> message; std::thread physicsThread(physicsLoop, smgr, &message, &positionRequests, &animationRequests, &rotationRequests); // Render loop while(render) { // Suspend physics loop and perform requested movement/rotations/animations if(positionRequests.size() > 0 || animationRequests.size() > 0 || rotationRequests.size() > 0){ message.insert(std::pair<std::string, std::string>("", "")); for(auto const &request : positionRequests) { Ogre::Vector3 pos = request.second; Ogre::SceneNode* sceneNode = request.first->getParentSceneNode(); sceneNode->setPosition(pos); } for(auto const &request : animationRequests) { request.first->getAnimationState(request.second)->addTime(0.1); } for(auto const &request : rotationRequests) { Ogre::SceneNode* sceneNode = request.first->getParentSceneNode(); sceneNode->roll(Ogre::Degree(request.second[0])); sceneNode->pitch(Ogre::Degree(request.second[1])); sceneNode->yaw(Ogre::Degree(request.second[2])); } positionRequests.clear(); animationRequests.clear(); rotationRequests.clear(); // Resume physics loop message.clear(); } // Update Ogre window Ogre::WindowEventUtilities::messagePump(); // Advance textureset index textureSet->CurrentIndex = (textureSet->CurrentIndex + 1) % textureSet->TextureCount; // Capture user input mKeyboard->capture(); mMouse->capture(); // Movement calculations mPlayerNode->translate(mDirection, Ogre::Node::TS_LOCAL); hmdFrameTiming = ovr_GetFrameTiming(hmd, 0); ts = ovr_GetTrackingState(hmd, hmdFrameTiming.DisplayMidpointSeconds); pose = ts.HeadPose.ThePose; ovr_CalcEyePoses(pose, offset, layer.RenderPose); oculusOrient = pose.Rotation; oculusPos = pose.Translation; mHeadNode->setOrientation(Ogre::Quaternion(oculusOrient.w, oculusOrient.x, oculusOrient.y, oculusOrient.z) * initialOculusOrientation.Inverse()); // Apply head tracking mHeadNode->setPosition(headPositionTrackingSensitivity * Ogre::Vector3(oculusPos.x, oculusPos.y,oculusPos.z)); // Update Ogre viewports root->_fireFrameRenderingQueued(); vpts[left]->update(); vpts[right]->update(); // Copy the rendered image to the Oculus Swap Texture glCopyImageSubData(renderTextureID, GL_TEXTURE_2D, 0, 0, 0, 0, ((ovrGLTexture*)(&textureSet->Textures[textureSet->CurrentIndex]))->OGL.TexId, GL_TEXTURE_2D, 0, 0, 0, 0, bufferSize.w,bufferSize.h, 1); layers = &layer.Header; // Submit new frame to the Oculus and update window ovr_SubmitFrame(hmd, 0, nullptr, &layers, 1); window->update(); // Exit loop when window is closed if(window->isClosed()) render = false; } // Shud down Oculus ovr_Destroy(hmd); ovr_Shutdown(); // Delete Ogre root and return delete root; return EXIT_SUCCESS; }
/*! Initialisation of Ogre. Load the plugins that are specified in the plugins.cfg or plugins_d.cfg files. These files are located in VISP_HAVE_OGRE_PLUGINS_PATH folder that is defined in vpConfig.h. Note that plugins.cfg file is always considered under Unix platforms. The file plugins_d.cfg is only considered under Windows when the build type is Debug. Load also the resources that are defined in the resources.cfg file. This file is located in VISP_HAVE_OGRE_RESOURCES_PATH folder that is defined in vpConfig.h. \param bufferedKeys : If true, use of buffered input for the keyboard (see Ogre documentation). Note that this parameter is only useful if OIS is used. \param hidden : If true, the created window will be hidden. Note that this functionnality requires Ogre3D 1.8.1 at least. \exception vpException::ioError : If the required plugins.cfg / plugins_d.cfg or resources.cfg files are not accessible. */ void vpAROgre::init(bool #ifdef VISP_HAVE_OIS bufferedKeys #endif ,bool hidden ) { // Create the root // mPluginsPath may contain more than one folder location separated by ";" bool pluginsFileExists = false; std::string pluginFile; std::vector<std::string> plugingsPaths = vpIoTools::splitChain(std::string(mPluginsPath), std::string(";")); for (size_t i=0; i<plugingsPaths.size(); i++) { #if defined(NDEBUG) || !defined(_WIN32) pluginFile = plugingsPaths[i]+"/plugins.cfg"; #else pluginFile = plugingsPaths[i]+"/plugins_d.cfg"; #endif if(vpIoTools::checkFilename(pluginFile)) { pluginsFileExists = true; break; } } if (! pluginsFileExists) { std::string errorMsg = std::string("Error: the requested plugins file \"") #if defined(NDEBUG) || !defined(_WIN32) + std::string("plugins.cfg") #else + std::string("plugins_d.cfg") #endif + std::string("\" doesn't exist in ") + std::string(mPluginsPath); std::cout << errorMsg << std::endl; throw (vpException(vpException::ioError, errorMsg)); } std::cout << "######################### Load plugin file: " << pluginFile << std::endl; if(Ogre::Root::getSingletonPtr() == NULL) mRoot = new Ogre::Root(pluginFile, "ogre.cfg", "Ogre.log"); else mRoot = Ogre::Root::getSingletonPtr(); // Load resource paths from config file // File format is: // [ResourceGroupName] // ArchiveType=Path // .. repeat // For example: // [General] // FileSystem=media/ // Zip=packages/level1.zip // mResourcePath may contain more than one folder location separated by ";" bool resourcesFileExists = false; std::string resourceFile; std::vector<std::string> resourcesPaths = vpIoTools::splitChain(std::string(mResourcePath), std::string(";")); for (size_t i=0; i<resourcesPaths.size(); i++) { resourceFile = resourcesPaths[i]+"/resources.cfg"; if(vpIoTools::checkFilename(resourceFile)) { resourcesFileExists = true; break; } } if (! resourcesFileExists) { std::string errorMsg = std::string("Error: the requested resource file \"resources.cfg\"") + std::string("doesn't exist in ") + std::string(mResourcePath); std::cout << errorMsg << std::endl; throw (vpException(vpException::ioError, errorMsg)); } std::cout << "######################### Load resource file: " << resourceFile << std::endl; Ogre::ConfigFile cf; cf.load(resourceFile); // Go through all sections & settings in the file Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); Ogre::String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } std::cout << "##################### add resources" << std::endl; //Add optionnal resources (given by the user). for(std::list<std::string>::const_iterator iter = mOptionnalResourceLocation.begin(); iter != mOptionnalResourceLocation.end(); ++iter){ Ogre::ResourceGroupManager::getSingleton().addResourceLocation(*iter, "FileSystem", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); } // Create the window bool canInit = true; if(mshowConfigDialog){ mRoot->restoreConfig(); if(!mRoot->showConfigDialog()) canInit = false; } else{ if(!mRoot->restoreConfig()) canInit = false; } if(!mRoot->isInitialised()){ if(!canInit){ //We set the default renderer system const Ogre::RenderSystemList& lRenderSystemList = mRoot->getAvailableRenderers(); if( lRenderSystemList.size() == 0 ) throw "ConfigDialog aborted"; // Exit the application on cancel Ogre::RenderSystem *lRenderSystem = lRenderSystemList.at(0); std::cout << "Using " << lRenderSystem->getName() << " as renderer." << std::endl; mRoot->setRenderSystem(lRenderSystem); } mRoot->initialise(false); } bool fullscreen = false; Ogre::NameValuePairList misc; Ogre::ConfigOptionMap config = mRoot->getRenderSystem()->getConfigOptions(); Ogre::ConfigOptionMap::const_iterator it = config.begin(); while( it != config.end() ){ Ogre::String leftconf = (*it).first; Ogre::String rightconf = (*it).second.currentValue; if(leftconf == "Video Mode"){ if(canInit) { int ret = sscanf(rightconf.c_str(), "%d %*s %d", &mWindowWidth, &mWindowHeight); if (ret == 0) std::cout << "Cannot read Ogre video mode" << std::endl; } else{ if(mWindowWidth == 0 && mWindowHeight == 0){ mWindowWidth = mBackgroundWidth; mWindowHeight = mBackgroundHeight; } } } else if( leftconf == "Full Screen" ){ if(canInit){ if(rightconf == "Yes") fullscreen = true; } } else misc[leftconf] = rightconf; it++; } // With Ogre version >= 1.8.1 we hide the window if( hidden ){ #if ( OGRE_VERSION >= (1 << 16 | 8 << 8 | 1) ) misc["hidden"] = "true"; windowHidden = true; #endif } mWindow = mRoot->createRenderWindow(name, mWindowWidth, mWindowHeight, fullscreen, &misc); // Initialise resources Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); //----------------------------------------------------- // 4 Create the SceneManager // // ST_GENERIC = octree // ST_EXTERIOR_CLOSE = simple terrain // ST_EXTERIOR_FAR = nature terrain (depreciated) // ST_EXTERIOR_REAL_FAR = paging landscape // ST_INTERIOR = Quake3 BSP //----------------------------------------------------- mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); // Create the camera createCamera(); // Create a viewport Ogre::Viewport* viewPort = mWindow->addViewport(mCamera); // Ogre::Viewport* viewPort = mCamera->getViewport(); viewPort->setClearEveryFrame(true); // Set the projection parameters to match the camera intrinsic parameters updateCameraProjection(); // Create the 3D scene createScene(); // Initialise and register event handlers mRoot->addFrameListener(this); // Register as a Window listener Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this); #ifdef VISP_HAVE_OIS // Initialise OIS Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); OIS::ParamList pl; size_t windowHnd = 0; std::ostringstream windowHndStr; // Initialise window mWindow->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); // Let the user use the keyboard elsewhere #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX pl.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false"))); #endif mInputManager = OIS::InputManager::createInputSystem( pl ); //Create all devices // Here we only consider the keyboard input mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, bufferedKeys )); if ( !bufferedKeys ) mKeyboard->setEventCallback ( this); #endif // Initialise a render to texture to be able to retrieve a screenshot Ogre::TexturePtr Texture = Ogre::TextureManager::getSingleton().createManual("rtf", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,Ogre::TEX_TYPE_2D, mWindow->getWidth(),mWindow->getHeight(), 0, Ogre::PF_R8G8B8A8, Ogre::TU_RENDERTARGET); // Ogre::TexturePtr Texture = Ogre::TextureManager::getSingleton().createManual("rtf", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,Ogre::TEX_TYPE_2D, // 640,480, 0, Ogre::PF_R8G8B8A8, Ogre::TU_RENDERTARGET); Ogre::RenderTexture* RTarget = Texture->getBuffer()->getRenderTarget(); /*Ogre::Viewport* Viewport =*/ RTarget->addViewport(mCamera); RTarget->getViewport(0)->setClearEveryFrame(true); RTarget->getViewport(0)->setOverlaysEnabled(false); }