Welcome to the new Ogre Wiki!
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
This is the source for Basic Tutorial 6.
#include <Ogre.h> #include <OIS/OIS.h> #include <CEGUI/CEGUI.h> #include <CEGUI/RendererModules/Ogre/CEGUIOgreRenderer.h> using namespace Ogre; class ExitListener : public FrameListener { public: ExitListener(OIS::Keyboard *keyboard) : mKeyboard(keyboard) { } bool frameStarted(const FrameEvent& evt) { mKeyboard->capture(); return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); } private: OIS::Keyboard *mKeyboard; }; class Application { public: void go() { createRoot(); defineResources(); setupRenderSystem(); createRenderWindow(); initializeResourceGroups(); setupScene(); setupInputSystem(); setupCEGUI(); createFrameListener(); startRenderLoop(); } ~Application() { mInputManager->destroyInputObject(mKeyboard); OIS::InputManager::destroyInputSystem(mInputManager); CEGUI::OgreRenderer::destroySystem(); delete mListener; delete mRoot; } private: Root *mRoot; OIS::Keyboard *mKeyboard; OIS::InputManager *mInputManager; CEGUI::OgreRenderer *mRenderer; ExitListener *mListener; void createRoot() { mRoot = new Root(); } void defineResources() { String secName, typeName, archName; ConfigFile cf; cf.load("resources.cfg"); ConfigFile::SectionIterator seci = cf.getSectionIterator(); while (seci.hasMoreElements()) { secName = seci.peekNextKey(); ConfigFile::SettingsMultiMap *settings = seci.getNext(); ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName); } } } void setupRenderSystem() { if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) throw Exception(52, "User canceled the config dialog!", "Application::setupRenderSystem()"); //// Do not add this to the application //RenderSystem *rs = mRoot->getRenderSystemByName("Direct3D9 Rendering Subsystem"); // // or use "OpenGL Rendering Subsystem" //mRoot->setRenderSystem(rs); //rs->setConfigOption("Full Screen", "No"); //rs->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour"); } void createRenderWindow() { mRoot->initialise(true, "Tutorial Render Window"); //// Do not add this to the application //mRoot->initialise(false); //HWND hWnd = 0; // Get the hWnd of the application! //NameValuePairList misc; //misc["externalWindowHandle"] = StringConverter::toString((int)hWnd); //RenderWindow *win = mRoot->createRenderWindow("Main RenderWindow", 800, 600, false, &misc); } void initializeResourceGroups() { TextureManager::getSingleton().setDefaultNumMipmaps(5); ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); } void setupScene() { SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager"); Camera *cam = mgr->createCamera("Camera"); Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); } void setupInputSystem() { size_t windowHnd = 0; std::ostringstream windowHndStr; OIS::ParamList pl; RenderWindow *win = mRoot->getAutoCreatedWindow(); win->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); mInputManager = OIS::InputManager::createInputSystem(pl); try { mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); //mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); //mJoy = static_cast<OIS::JoyStick*>(mInputManager->createInputObject(OIS::OISJoyStick, false)); } catch (const OIS::Exception &e) { throw new Exception(42, e.eText, "Application::setupInputSystem"); } } void setupCEGUI() { // CEGUI setup mRenderer = &CEGUI::OgreRenderer::bootstrapSystem(); // Other CEGUI setup here. } void createFrameListener() { mListener = new ExitListener(mKeyboard); mRoot->addFrameListener(mListener); } void startRenderLoop() { mRoot->startRendering(); //// Do not add this to the application //while (mRoot->renderOneFrame()) //{ // // Do some things here, like sleep for x milliseconds or perform other actions. // // However, make sure you call the display update function: // WindowEventUtilities::messagePump(); //} } }; #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include "windows.h" INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) #else int main(int argc, char **argv) #endif { try { Application app; app.go(); } catch(Exception& e) { #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else fprintf(stderr, "An exception has occurred: %s\n", e.getFullDescription().c_str()); #endif } return 0; }
Contributors to this page: jacmoe
.
Page last modified on Friday 02 of July, 2010 06:13:26 UTC by jacmoe
.
The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.
Sidebar
Last changes
- Hydrax
- QtOgre
- SoC2012 Complete the DirectX 11 render system
- SoC2012 Volume Rendering with LOD aimed at terrain
- SoC2012 Improve and Demo the Terrain System
- Mogre and WPF
- SoC2012 Implementation of Off-Screen Particles
- Advanced Ogre Framework
- Ogre overlays using Qt
- Architecture and Design in Games
Search box
Online users
53
online users

