- Dll & Lib
批生成MyGUI Ogre渲染系统解决方案的Common工程,并将Bin与Lib目录拷贝到$(OGRE_HOME)目录下。
- resources_d.cfg
FileSystem=E:/MyGUI/MyGUI_3.2.0/Media/MyGUI_Media
- 环境变量
setx -m MYGUI_HOME "E:\MyGUI\MyGUI_3.2.0"
- 工作目录
$(OGRE_HOME)\bin\$(Configuration)
- 附加包含目录
$(OGRE_HOME)\include;$(OGRE_HOME)\boost;$(OGRE_HOME)\include\OGRE;$(MYGUI_HOME)\MyGUIEngine\include;$(MYGUI_HOME)\Platforms\Ogre\OgrePlatform\include;%(AdditionalIncludeDirectories)
- 附加库目录
$(OGRE_HOME)\lib\$(Configuration);$(OGRE_HOME)\boost\lib;$(MYGUI_HOME)\lib\$(Configuration);%(AdditionalLibraryDirectories)
- 附加依赖项
OgreMain_d.lib;OIS_d.lib;MyGUIEngine_d.lib;MyGUI.OgrePlatform_d.lib;%(AdditionalDependencies)
- System.h
/*************************************************** ©2014 Pf_D. All rights reserved. ***************************************************/ #pragma once #include "OGRE\Ogre.h" #include "OIS\OIS.h" #include "MyGUI.h" #include "MyGUI_OgrePlatform.h" class cAppInputListener : public OIS::KeyListener, public OIS::MouseListener { public: virtual bool keyPressed(const OIS::KeyEvent &arg); virtual bool keyReleased(const OIS::KeyEvent &arg); virtual bool mouseMoved(const OIS::MouseEvent &arg); virtual bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id); virtual bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); }; class cAppFrameListener : public Ogre::FrameListener { private: OIS::InputManager *mInputMgr; OIS::Keyboard *mKeyboard; OIS::Mouse *mMouse; public: cAppFrameListener(Ogre::RenderWindow *win); bool frameStarted(const Ogre::FrameEvent &evt); bool frameRenderingQueued(const Ogre::FrameEvent &evt); bool frameEnded(const Ogre::FrameEvent &evt); }; class cApplication { protected: MyGUI::Gui *mGUI; MyGUI::OgrePlatform *mPlatform; Ogre::Root *mRoot; Ogre::RenderWindow *mWindow; Ogre::SceneManager *mSceneMgr; public: void setupResources(); virtual void createScene() {} bool setup(); void go(); };
- System.cpp
/*************************************************** ©2014 Pf_D. All rights reserved. ***************************************************/ #include "System.h" bool cAppInputListener::keyPressed(const OIS::KeyEvent &arg) { MyGUI::InputManager::getInstance().injectKeyPress( MyGUI::KeyCode::Enum(arg.key), arg.text); // ... return true; } bool cAppInputListener::keyReleased(const OIS::KeyEvent &arg) { MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::Enum(arg.key)); // ... return true; } bool cAppInputListener::mouseMoved( const OIS::MouseEvent &arg ) { MyGUI::InputManager::getInstance().injectMouseMove( arg.state.X.abs, arg.state.Y.abs, arg.state.Z.abs); // ... return true; } bool cAppInputListener::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) { MyGUI::InputManager::getInstance().injectMousePress( arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); // ... return true; } bool cAppInputListener::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) { MyGUI::InputManager::getInstance().injectMouseRelease( arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id)); // ... return true; } cAppFrameListener::cAppFrameListener(Ogre::RenderWindow *win) { OIS::ParamList parameters; unsigned int windowHandle = 0; std::ostringstream windowHandleString; win->getCustomAttribute("WINDOW", &windowHandle); windowHandleString << windowHandle; parameters.insert(std::make_pair("WINDOW", windowHandleString.str())); mInputMgr = OIS::InputManager::createInputSystem(parameters); cAppInputListener *inputListener = new cAppInputListener(); mKeyboard = static_cast<OIS::Keyboard*>(mInputMgr->createInputObject(OIS::OISKeyboard, true)); mKeyboard->setEventCallback(inputListener); mMouse = static_cast<OIS::Mouse*>(mInputMgr->createInputObject(OIS::OISMouse, true)); const OIS::MouseState &mouseState = mMouse->getMouseState(); mouseState.width = win->getWidth(); mouseState.height = win->getHeight(); mMouse->setEventCallback(inputListener); } bool cAppFrameListener::frameStarted(const Ogre::FrameEvent &evt) { mKeyboard->capture(); mMouse->capture(); return true; } bool cAppFrameListener::frameRenderingQueued(const Ogre::FrameEvent &evt) { return true; } bool cAppFrameListener::frameEnded(const Ogre::FrameEvent &evt) { return true; } void cApplication::setupResources() { Ogre::ConfigFile cf; #if OGRE_DEBUG_MODE cf.load("resources_d.cfg"); #else cf.load("resources.cfg"); #endif Ogre::ConfigFile::SectionIterator secIter = cf.getSectionIterator(); Ogre::String secName, typeName, archName; while(secIter.hasMoreElements()) { secName = secIter.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = secIter.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); } } } bool cApplication::setup() { #ifndef OGRE_STATIC_LIB #if OGRE_DEBUG_MODE mRoot = OGRE_NEW Ogre::Root("plugins_d.cfg"); #else mRoot = OGRE_NEW Ogre::Root("plugins.cfg"); #endif #endif setupResources(); if(!mRoot->showConfigDialog()) return false; mWindow = mRoot->initialise(true); // Choose scene manager mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); // Create camera Ogre::Camera *cam = mSceneMgr->createCamera("Camera"); cam->setPosition(Ogre::Vector3(0, 0, 50)); cam->lookAt(Ogre::Vector3(0, 0, -300)); cam->setNearClipDistance(5); // Create viewports Ogre::Viewport *vp = mWindow->addViewport(cam); vp->setBackgroundColour(Ogre::ColourValue(0, 0, 0)); cam->setAspectRatio(Ogre::Real(vp->getActualWidth())/Ogre::Real(vp->getActualHeight())); // Load resources Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // Create scene createScene(); // Create frame listener mRoot->addFrameListener(new cAppFrameListener(mWindow)); return true; } void cApplication::go() { if(!setup()) return; mRoot->startRendering(); }
- Main.cpp
/*************************************************** ©2014 Pf_D. All rights reserved. ***************************************************/ #include "System.h" class cMyApplication : public cApplication { public: void createScene() { // MyGUI mPlatform = new MyGUI::OgrePlatform(); mPlatform->initialise(mWindow, mSceneMgr); mGUI = new MyGUI::Gui(); mGUI->initialise(); MyGUI::ButtonPtr button = mGUI->createWidget<MyGUI::Button> ("Button", 10, 10, 300, 26, MyGUI::Align::Default, "Main"); button->setCaption("exit"); button->eventMouseButtonClick += MyGUI::newDelegate(this, &cMyApplication::notifyExitClick); mSceneMgr->setAmbientLight(Ogre::ColourValue::White); Ogre::Entity *ent = mSceneMgr->createEntity("Sinbad", "Sinbad.mesh"); mSceneMgr->getRootSceneNode()->attachObject(ent); } void notifyExitClick(MyGUI::WidgetPtr sender) { exit(0); } }; int main() { cMyApplication App; App.go(); return 0; }
时间: 2025-01-18 12:39:38