OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: BasicTutorial6SourceCurrent
View page
Source of version: 3
(current)
{CODE(caption="TutorialApplication.h" wrap="1" colors="c++")} #ifndef TUTORIALAPPLICATION_H #define TUTORIALAPPLICATION_H #include <OgreRoot.h> #include <OgreWindowEventUtilities.h> #include <OISEvents.h> #include <OISInputManager.h> #include <OISKeyboard.h> #include <OISMouse.h> class TutorialApplication : public Ogre::WindowEventListener, public Ogre::FrameListener { public: TutorialApplication(); virtual ~TutorialApplication(); bool go(); private: virtual bool frameRenderingQueued(const Ogre::FrameEvent& fe); virtual void windowResized(Ogre::RenderWindow* rw); virtual void windowClosed(Ogre::RenderWindow* rw); Ogre::Root* mRoot; Ogre::String mResourcesCfg; Ogre::String mPluginsCfg; Ogre::RenderWindow* mWindow; Ogre::SceneManager* mSceneMgr; Ogre::Camera* mCamera; OIS::InputManager* mInputMgr; OIS::Keyboard* mKeyboard; OIS::Mouse* mMouse; }; #endif {CODE} {CODE(caption="TutorialApplication.cpp" wrap="1" colors="c++")} #include "TutorialApplication.h" #include <OgreEntity.h> #include <OgreCamera.h> #include <OgreViewport.h> #include <OgreSceneManager.h> #include <OgreRenderWindow.h> #include <OgreConfigFile.h> #include <OgreException.h> TutorialApplication::TutorialApplication() : mRoot(0), mResourcesCfg(Ogre::StringUtil::BLANK), mPluginsCfg(Ogre::StringUtil::BLANK), mWindow(0), mSceneMgr(0), mCamera(0), mInputMgr(0), mMouse(0), mKeyboard(0) { } TutorialApplication::~TutorialApplication() { Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this); windowClosed(mWindow); delete mRoot; } bool TutorialApplication::go() { #ifdef _DEBUG mResourcesCfg = "resources_d.cfg"; mPluginsCfg = "plugins_d.cfg"; #else mResourcesCfg = "resources.cfg"; mPluginsCfg = "plugins.cfg"; #endif mRoot = new Ogre::Root(mPluginsCfg); Ogre::ConfigFile cf; cf.load(mResourcesCfg); Ogre::String name, locType; Ogre::ConfigFile::SectionIterator secIt = cf.getSectionIterator(); while (secIt.hasMoreElements()) { Ogre::ConfigFile::SettingsMultiMap* settings = secIt.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator it; for (it = settings->begin(); it != settings->end(); ++it) { locType = it->first; name = it->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation(name, locType); } } if (!(mRoot->restoreConfig() || mRoot->showConfigDialog())) return false; mWindow = mRoot->initialise(true, "TutorialApplication Render Window"); Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); mCamera = mSceneMgr->createCamera("MainCam"); mCamera->setPosition(0, 0, 80); mCamera->lookAt(0, 0, -300); mCamera->setNearClipDistance(5); Ogre::Viewport* vp = mWindow->addViewport(mCamera); vp->setBackgroundColour(Ogre::ColourValue(0, 0, 0)); mCamera->setAspectRatio( Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); // Create Scene Ogre::Entity* ogreEntity = mSceneMgr->createEntity("ogrehead.mesh"); Ogre::SceneNode* ogreNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); ogreNode->attachObject(ogreEntity); mSceneMgr->setAmbientLight(Ogre::ColourValue(.5, .5, .5)); Ogre::Light* light = mSceneMgr->createLight("MainLight"); light->setPosition(20, 80, 50); // OIS Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); OIS::ParamList pl; size_t windowHandle = 0; std::ostringstream windowHandleStr; mWindow->getCustomAttribute("WINDOW", &windowHandle); windowHandleStr << windowHandle; pl.insert(std::make_pair(std::string("WINDOW"), windowHandleStr.str())); mInputMgr = OIS::InputManager::createInputSystem(pl); mKeyboard = static_cast<OIS::Keyboard*>( mInputMgr->createInputObject(OIS::OISKeyboard, false)); mMouse = static_cast<OIS::Mouse*>( mInputMgr->createInputObject(OIS::OISMouse, false)); windowResized(mWindow); Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this); mRoot->addFrameListener(this); mRoot->startRendering(); return true; } bool TutorialApplication::frameRenderingQueued(const Ogre::FrameEvent& fe) { if (mWindow->isClosed()) return false; mKeyboard->capture(); mMouse->capture(); if (mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; return true; } void TutorialApplication::windowResized(Ogre::RenderWindow* rw) { int left, top; unsigned int width, height, depth; rw->getMetrics(width, height, depth, left, top); const OIS::MouseState& ms = mMouse->getMouseState(); ms.width = width; ms.height = height; } void TutorialApplication::windowClosed(Ogre::RenderWindow* rw) { if(rw == mWindow) { if(mInputMgr) { mInputMgr->destroyInputObject(mMouse); mInputMgr->destroyInputObject(mKeyboard); OIS::InputManager::destroyInputSystem(mInputMgr); mInputMgr = 0; } } } #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include "windows.h" #endif #ifdef __cplusplus extern "C" { #endif #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) #else int main(int argc, char *argv[]) #endif { TutorialApplication app; try { app.go(); } catch(Ogre::Exception& e) { #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl; #endif } return 0; } #ifdef __cplusplus } #endif {CODE}
Search by Tags
Search Wiki by Freetags
Latest Changes
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
Critter AI
Mogre Add-ons
MOGRE
Mogre MyGUI wrapper
MOGRE Editable Terrain Manager
...more
Search
Find
Advanced
Search Help
Online Users
58 online users